An easier alternative to using gather is using python indexing.
Let’s say you have your input (size (16, 8, 5)), and indices of size (16, 1) that contain a number in the range [0, 8).  Then one thing you can do is:
count = torch.arange(16)  # get numbers from 0..15
indices = indices.squeeze()  # indices is now size `(16,)`
input[count, indices, :]  # gives an output of size (16, 5).