How to use pre-trained embeddings in OpenNMT-tf?

tensorflow

(liweikang) #1

When i using the OpenNMT-tf,I can add pretrained Embedding,can someone help me?


(Guillaume Klein) #2

Hello,

In the model configuration, you should first declare that your WordEmbedder uses pretrained embeddings, e.g.:

source_inputter=onmt.inputters.WordEmbedder(
    vocabulary_file_key="source_word_vocabulary",
    embedding_file_key="source_word_embeddings")

(See the WordEmbedder constructor for additional options.)

In the run configuration, you should give the path to the pretrained embeddings, e.g.:

data:
  source_words_vocabulary: data/vocab.txt
  source_words_embeddings: data/glove.txt

See also the documentation of the load_pretrained_embeddings function to learn about the file format and loading behavior.


(Mahjabeen Sust) #3

Can I use target_words_embeddings instead of source? What possible changes it could make in output?


(Guillaume Klein) #4

Can I use target_words_embeddings instead of source?

Yes it’s the same syntax for the target.

What possible changes it could make in output?

Most likely, it will only make the training converge faster.