Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEA: Add Interaction features of the history items for sequential dataloader #547

Merged
merged 4 commits into from
Dec 5, 2020
Merged
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
31 changes: 29 additions & 2 deletions recbole/data/dataloader/sequential_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ def __init__(self, config, dataset,
self.target_time_field = self.time_field
self.item_list_length_field = config['ITEM_LIST_LENGTH_FIELD']

for field in dataset.inter_feat:
if field not in [self.uid_field, self.iid_field, self.time_field]:
ftype = dataset.field2type[field]
setattr(self, f'{field}_list_field', field + list_suffix)
if dataset.field2type[field] == FeatureType.TOKEN:
dataset.set_field_property(getattr(self, f'{field}_list_field'), FeatureType.TOKEN_SEQ,
FeatureSource.INTERACTION,
self.max_item_list_len)
elif dataset.field2type[field] == FeatureType.FLOAT:
dataset.set_field_property(getattr(self, f'{field}_list_field'), FeatureType.FLOAT_SEQ,
FeatureSource.INTERACTION,
self.max_item_list_len)
else:
raise NotImplementedError('Field with ftype [{}] is not implemented for sequential model'.format(ftype))

dataset.set_field_property(self.item_list_field, FeatureType.TOKEN_SEQ, FeatureSource.INTERACTION,
self.max_item_list_len)
dataset.set_field_property(self.time_list_field, FeatureType.FLOAT_SEQ, FeatureSource.INTERACTION,
Expand Down Expand Up @@ -134,8 +149,20 @@ def augmentation(self, uid_list, item_list_index, target_index, item_list_length
self.item_list_length_field: item_list_length,
}
for field in self.dataset.inter_feat:
if field != self.iid_field and field != self.time_field:
if field not in [self.uid_field, self.iid_field, self.time_field]:
new_dict[field] = self.dataset.inter_feat[field][target_index].values
"""Add extra field feature for interaction"""
ftype = self.dataset.field2type[field]
if ftype == FeatureType.TOKEN or ftype == FeatureType.FLOAT:
field_value = self.dataset.inter_feat[field]
dtype = np.int64 if ftype == FeatureType.TOKEN else np.float32
new_dict[getattr(self, f'{field}_list_field')] = np.zeros((new_length, self.max_item_list_len),
dtype=dtype)
for i, (index, length) in enumerate(zip(item_list_index, item_list_length)):
new_dict[getattr(self, f'{field}_list_field')][i][:length] = field_value[index]
else:
raise NotImplementedError('Field with ftype [{}] is not implemented for sequential model'.format(ftype))

if self.position_field:
new_dict[self.position_field] = np.tile(np.arange(self.max_item_list_len), (new_length, 1))

Expand Down Expand Up @@ -284,4 +311,4 @@ def get_pos_len_list(self):
Returns:
np.ndarray or list: Number of positive item for each user in a training/evaluating epoch.
"""
return np.ones(self.pr_end, dtype=np.int64)
return np.ones(self.pr_end, dtype=np.int64)