Ok this is quite old topic, but I though that people might still wonder about this, so here goes.
I’ve tried what you proposed and if I am not wrong what you should do, is keep an index to weights dict when you initially encode your strings to ids (in data.py) and later in the model instead of creating the encoder (which is an nn.Embeddings module) weights dynamically, you pass the weights of the indexes you accumulated.
So one should replace:

  
      github.com
  
  
    pytorch/examples/blob/81f47e8ea49c74494d2aa8dc1c9c4ddc6c0eca73/word_language_model/model.py#L40 1

        self.decoder.weight = self.encoder.weight


    self.init_weights()


    self.rnn_type = rnn_type
    self.nhid = nhid
    self.nlayers = nlayers


def init_weights(self):
    initrange = 0.1
    self.encoder.weight.data.uniform_(-initrange, initrange)
    self.decoder.bias.data.zero_()
    self.decoder.weight.data.uniform_(-initrange, initrange)


def forward(self, input, hidden):
    emb = self.drop(self.encoder(input))
    output, hidden = self.rnn(emb, hidden)
    output = self.drop(output)
    decoded = self.decoder(output.view(output.size(0)*output.size(1), output.size(2)))
    return decoded.view(output.size(0), output.size(1), decoded.size(1)), hidden





  
  
    
    
  
  


with something along the lines (suppose the vectors is the idx to weights dict)
w = list(vectors.values())
weights = np.asarray(w, dtype=np.float32)

self.encoder.weight.data.copy_(torch.from_numpy(weights))