Hi,
I couldn’t understand from the documentation what the narrow
method does on a tensor, the example doesn’t make sense to me
More specifically, I’m trying to understand what’s going in this code (from https://github.com/pytorch/examples/tree/master/word_language_model):
def batchify(data, bsz):
# Work out how cleanly we can divide the dataset into bsz parts.
nbatch = data.size(0) // bsz
# Trim off any extra elements that wouldn't cleanly fit (remainders).
data = data.narrow(0, 0, nbatch * bsz)
# Evenly divide the data across the bsz batches.
data = data.view(bsz, -1).t().contiguous()
return data.to(device)
Thanks!