Pytorch nn.embedding error
I was reading pytorch documentation on Word Embedding. 

import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim

torch.manual_seed(5)

word_to_ix = {"hello": 0, "world": 1, "how":2, "are":3, "you":4}
embeds = nn.Embedding(2, 5)  # 2 words in vocab, 5 dimensional embeddings
lookup_tensor = torch.tensor(word_to_ix["hello"], dtype=torch.long)
hello_embed = embeds(lookup_tensor)
print(hello_embed)


Output:

tensor([-0.4868, -0.6038, -0.5581,  0.6675, -0.1974])


This looks good but if I replace  line lookup_tensor by 

lookup_tensor = torch.tensor(word_to_ix["how"], dtype=torch.long)


I am getting the error as:

RuntimeError: index out of range at /Users/soumith/minicondabuild3/conda-bld/pytorch_1524590658547/work/aten/src/TH/generic/THTensorMath.c:343

I don't understand why it gives RunTime error on line hello_embed = embeds(lookup_tensor). 

When you declare embeds = nn.Embedding(2, 5) the vocab size is 2 and embedding size is 5. i.e each word will be represented by a vector of size 5 and there are only 2 words in vocab.

lookup_tensor = torch.tensor(word_to_ix["how"], dtype=torch.long) embeds will try to look up vector corresponding to the third word in vocab, but embedding has vocab size of 2. and that is why you get the error.

If you declare embeds = nn.Embedding(5, 5) it should work fine.
