Skip to content

Instantly share code, notes, and snippets.

@MLWhiz
Created September 6, 2020 12:30
Show Gist options
  • Select an option

  • Save MLWhiz/77323a18d92e755858bc5ce01f04360c to your computer and use it in GitHub Desktop.

Select an option

Save MLWhiz/77323a18d92e755858bc5ce01f04360c to your computer and use it in GitHub Desktop.
class CustomTextDataset(Dataset):
'''
Simple Dataset initializes with X and y vectors
We start by sorting our X and y vectors by sequence lengths
'''
def __init__(self,X,y=None):
self.data = list(zip(X,y))
# Sort by length of first element in tuple
self.data = sorted(self.data, key=lambda x: len(x[0]))
def __len__(self):
return len(self.data)
def __getitem__(self, idx):
return self.data[idx]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment