Ok, as I said, try just removing “lookback” variable or setting it to high value to limit max sequence length. Note that batches will then contain sequences of variable length, combined with padding, so loss mask should be added, something like:
loss = (F.hinge_embedding_loss(output[0], y.long(), reduction='none') * lossmask).sum() / lossmask.sum()

Actually, you need such a mask even with lookback=4, if shorter sequences exist.
I use this to create lossmask, but it is for time-major rnns
def create_seq_mask(seq_lengths : Tensor):
	max_seq_length = int(seq_lengths.max())
	n = len(seq_lengths)
	r = torch.zeros(max_seq_length, n, dtype=torch.float32)
	for i in range(n):
		r[:seq_lengths[i], i] = 1.0
	return r

Also I think your __getitem__ is buggy, as sample = [x,y], len(sample)=2, and you intended to use len(sample[0]).
Good luck.