How to run OpenNMT-py model to translate a given string in jupyter notebook?

739 Views Asked by At

The documentation only mentions using the command line to run the translate.py script already given in the OpenNMT-py repo, i.e. use

python translate.py -model model_name.pt -src data/src-test.txt -output pred.txt

and that's fine, but how do I use the onmt library to load the trained model in a jupyter notebook and make translations on the go? I want it to be able to do something like this in jupyter:

model = onmt.module.load(/path/to/model.pt)
text = "hola como estas"
model.translate(text)

Output:
>>>Hello how are you

I can't find any documentation on how to do this. Please help!

0

There are 0 best solutions below