Based on the error message it seems you are trying to index too many dimensions.
Assuming hidden has 3 dimensions, then hidden[0] would return a tensor with 2 dimensions only.
In that case, [-2, :, :] won’t work and you would have to remove one indexing dimension.