How do you use '-replace_unk' on server.py? (TranslationServer.py)

pytorch

#1

Hi, there. When you use a non-argument translational option like ‘-replace_unk’, how do you write conf.json?

Examining TranslationServer.py => class ServerModel => parse_opt(),
I suspected a line of this function prevents you from using such options:

for (k, v) in opt.itmes():
    sys.argv += ['-%s' % k, str(v)] # <== this line

So I wrote conf.json like:

{
    "models_root": "./available_models",
    "models": [
        {
            "id": 0,
            "model": "whatever.pt",
            "timeout": -1,
            "on_timeout": "unload",
            "load": true,
            "opt": {
                "gpu": 2,
                "beam_size": 5,
                "replace_unk": true # <== like a boolean
             }
        }
    ]
}

Then, I modified the line above like:

for (k, v) in opt.itmes():
    sys.argv += ['-%s' % k] if v == True else ['-%s' % k, str(v)]

This seems to be working fine. But I’m not sure if this is a bug or I just don’t know the correct way to specify such switches. Can somebody tell me?