Based on the error message the indexing operation is failing in once of these tensors:
encoder_target[idx]
# or
decoder_target[idx]

make sure the size of the tensors in dim0 is sufficiently large for the index.