Specifically in opennmt-py. Now there are many questions on this topic, such as Getting alignment/attention during translation in OpenNMT-py and the following thread on the opennmt forum https://github.com/OpenNMT/OpenNMT-py/issues/575. I use the code suggested by the latter. However none seem to address the problem I have. I try to run the following simple snippet of code.
import onmt
import onmt.inputters
import onmt.translate
import onmt.model_builder
from collections import namedtuple
Opt = namedtuple('Opt', ['models', 'data_type', 'reuse_copy_attn', "gpu"])
opt = Opt("/home/Desktop/hidden-att/model/hidden-2/seed-0/LSTMlang1_step_400.pt", "text",False, 0)
fields, model, model_opt = onmt.model_builder.load_test_model(opt,{"reuse_copy_attn":False})
I get this error trace.
Traceback (most recent call last):
File "<ipython-input-63-94c1f45c429f>", line 1, in <module>
runfile('/home/Desktop/hidden-att/graph_hidden_exp.py', wdir='/home/Desktop/hidden-att')
File "/home/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "/home/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/Desktop/hidden-att/graph_hidden_exp.py", line 33, in <module>
fields, model, model_opt = onmt.model_builder.load_test_model(opt,{"reuse_copy_attn":False})
File "../../Documents/NMT/OpenNMT-py/onmt/model_builder.py", line 85, in load_test_model
map_location=lambda storage, loc: storage)
File "/home/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 387, in load
return _load(f, map_location, pickle_module, **pickle_load_args)
File "/home/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 549, in _load
_check_seekable(f)
File "/home/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 194, in _check_seekable
raise_err_msg(["seek", "tell"], e)
File "/home/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 187, in raise_err_msg
raise type(e)(msg)
AttributeError: 'dict' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.
So has anyone experienced and solved this problem? Or know where to look? I guess it is something about the loaded file, but it is trained with opennmt-py in a fairly standard way.