The error message seems to be a bit strange.
It seems your target has the shape [batch_size, 1].
Could you remove dim1 using y = y.squeeze() and try it again?
Here is a simple dummy code where you can see the shapes:
vocab_size = 10000
model = nn.Sequential(
    nn.Linear(vocab_size, vocab_size),
    nn.LogSoftmax(dim=1)
)
criterion = nn.NLLLoss()

batch_size = 10
x = torch.randn(batch_size, vocab_size)
target = torch.randint(0, vocab_size, (batch_size, ))

print(x.shape)
> torch.Size([10, 10000])
print(target.shape)
> torch.Size([10])

output =model(x)
loss = criterion(output, target)
loss.backward()