OpenNMT Forum

Python Tool for language translation using OpenNMT

(Kishor Kp) #1

Dear ,

I am planning for creating a language translator POC for excel using OpenNMT.
For excel processing I am using Pandas. For using opennmt to translate using the existing model, I am
bit confused as to how to proceed ?

Please assist me here.

Thank you,

(Panos Kanavos) #2


So, you need a Python client for sending requests, right? If so, you can do it like this (this works for the Lua REST server):

import requests

def translate():
    url = "http://server_url:server_port/translator/translate"
    source = input("Enter sentence: ") # here grab your text from Excel with some way
    headers = {'content-type': 'application/json'}

    params = [{ "src" : source}]

    response =, json=params, headers=headers)

    target = response.json()


if __name__ == "__main__":

(Kishor Kp) #3

Dear Panos,

Thank you very much for the response.
What I understand is the following:

  1. I need to install translation server on my desktop.
  2. Excel translation tool would send requests to server
  3. Put the received responses back into the excel

Please correct if my understanding is incorrect.


(Panos Kanavos) #4

One way could be this I guess, since you won’t have to deal with tokenization and detokenization, but if your PC runs on Windows, I don’t know how easy it would be to setup everything. It would be best if you could have OpenNMT in a Linux machine and just send requests there.
Another, non-pythonic, way would be to compile and use OpenNMT’s CTranslate project which doesn’t require a server.

(Kishor Kp) #5

thanks for the update on this, Panos.
let me try one of these. In case of any issues, I would contact again…

(Kishor Kp) #6

Dear Panos,

As suggested, I have built the Linux system. How do I install the Translation Server on this .
I have the following issues:

  1. I am unable to find the installer for Translation Server (Language translation for supported models)
  2. The OpenNMT gives information about using lua . Foremost I do not know lua scripts.
    Secondly, I am not sure how do go ahead installing using these lua scripts.

Please guide me here.

Thank You,

(Panos Kanavos) #7


In your initial post you mentioned that you wanted to use an existing model, so I assumed you already have a working installation of OpenNMT. I suggest you read the documentation and follow the instructions about installing and using OpenNMT:

(Kishor Kp) #8

Hi Panos,

Thank you very much for the support here.