public code v1
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
from torch.utils.data import Dataset
|
||||
|
||||
|
||||
class UserItemRatingDataset(Dataset):
|
||||
"""Wrapper, convert <user, item, rating> Tensor into Pytorch Dataset"""
|
||||
|
||||
def __init__(self, user_tensor, item_tensor, target_tensor):
|
||||
"""
|
||||
args:
|
||||
|
||||
target_tensor: torch.Tensor, the corresponding rating for <user, item> pair
|
||||
"""
|
||||
self.user_tensor = user_tensor
|
||||
self.item_tensor = item_tensor
|
||||
self.target_tensor = target_tensor
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self.user_tensor[index], self.item_tensor[index], self.target_tensor[index]
|
||||
|
||||
def __len__(self):
|
||||
return self.user_tensor.size(0)
|
||||
Reference in New Issue
Block a user