OpenNMT

Running OpenNMT on Windows - AttributeError: ‘Namespace’ object has no attribute ‘fix_word_vecs_enc’

I have a translation model I’m trying to integrate in to a python application on Windows. I’ve successfully used the model on Linux Subsystem for Windows but when I try it on Windows I’m having problems.

I use the command:

onmt_translate -model path/to/model.pt -src path/to/source.txt -output path/to/output.txt -verbose -replace_unk

And get the following message:

Traceback (most recent call last):
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py”, line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py”, line 87, in run_code
exec(code, run_globals)
File "C:\Users\user\Documents\OpenNMT_app\venv\Scripts\onmt_translate.exe_main
.py", line 7, in
File “C:\Users\user\Documents\OpenNMT_app\venv\lib\site-packages\onmt\bin\translate.py”, line 48, in main
translate(opt)
File “C:\Users\user\Documents\OpenNMT_app\venv\lib\site-packages\onmt\bin\translate.py”, line 18, in translate
translator = build_translator(opt, logger=logger, report_score=True)
File “C:\Users\user\Documents\OpenNMT_app\venv\lib\site-packages\onmt\translate\translator.py”, line 28, in build_translator
fields, model, model_opt = load_test_model(opt)
File “C:\Users\user\Documents\OpenNMT_app\venv\lib\site-packages\onmt\model_builder.py”, line 108, in load_test_model
model = build_base_model(model_opt, fields, use_gpu(opt), checkpoint,
File “C:\Users\user\Documents\OpenNMT_app\venv\lib\site-packages\onmt\model_builder.py”, line 144, in build_base_model
src_emb = build_embeddings(model_opt, src_field)
File “C:\Users\user\Documents\OpenNMT_app\venv\lib\site-packages\onmt\model_builder.py”, line 47, in build_embeddings
fix_word_vecs = opt.fix_word_vecs_enc if for_encoder
AttributeError: ‘Namespace’ object has no attribute ‘fix_word_vecs_enc’

Anybody know why this happens on Windows and not on Linux or what I can do to fix it?

Found the answer to my question. In the GitHub repository (https://github.com/OpenNMT/OpenNMT-py) it says:

Some advanced features (e.g. working pretrained models or specific transforms) require extra packages, you can install them with:

pip install -r requirements.opt.txt

I did the install and it works now