OpenNMT Forum

How to change embeddings into torch serialized tensors (Glove embeddings)

I have some issues using Glove word embeddings.I generated the embeddings by following the author’s scripts and I know that they need to be torch serialized tensors if I want to use them in the train part. I found some tutorials in this forum where they use to generate the vocabulary file and then use to produce the tensors. My problem is that I couldn’t find in the github repository ( and I have no idea how to change the embeddings into tensors. Can someone help me to understand how to do this? is no longer since 2.0 release
Did you have a look at the updated entry in the FAQ?

So how can I create the tensors if doesn’t exist anymore?

It’s done on the fly here:

Can you explain to me how to perform this step by step? I have my word embeddings in a .txt file, what do I do from here? Sorry for the stupid question, but I’m very new to this.

The steps are documented in the link I already provided:

I managed to download OpenNMT-py 2.0, but I ran into another problem. This is the trace:

Traceback (most recent call last):
File “/…/…/envNMT/bin/onmt_train”, line 8, in
File “/…/…/envNMT/lib/python3.7/site-packages/onmt/bin/”, line 169, in main
File “/…/…/envNMT/lib/python3.7/site-packages/onmt/bin/”, line 103, in train
checkpoint, fields, transforms_cls = _init_train(opt)
File “/…/…/envNMT/lib/python3.7/site-packages/onmt/bin/”, line 58, in _init_train
File “/…/…/envNMT/lib/python3.7/site-packages/onmt/utils/”, line 131, in validate_prepare_opts
File “/…/…/envNMT/lib/python3.7/site-packages/onmt/utils/”, line 29, in _validate_data
for cname, corpus in corpora.items():
AttributeError: ‘str’ object has no attribute ‘items’

Can someone help me to understand what went wrong?

You need to make a valid yaml configuration, as shown in the docs: