So I’ve been thinking pretty much the same lately and in the light of FastText embeddings which by default produce UOV embeddings by using ngrams of words during training it makes more sense to have something in the nn.Embedding to handle such functionality.
Currently what I’ve been doing (I’m not sure is 100% correct) is the following:
def encode(self, data):
        encoded_sentences = []

        for sentence in data:
            for word in sentence:
                if word not in self.wordToIndex:
                    self.indexToWord.append(word)

                    idx = len(self.indexToWord) - 1
                    self.wordToIndex[word] = idx

                    # Get the current embeddings or create them on the fly (in your case)
                    self.vectors[idx] = self._embeddings[word]
                else:
                    idx = self.wordToIndex[word]

                encoded_sentence.append(idx)

            encoded_sentences.append(encoded_sentence)

Then the plan is to pass the .vectors property to the nn.Embedding weights. However this is really slow, considering that you have to go through every word just to create the weights to add to the nn.Embedding layer
What I don’t get is why not skip the whole word to index -> index to embedding step and have nn.Embedding handle words directly?