Python Tool for language translation using OpenNMT

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,
Kishor

Hi,

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 = requests.post(url, json=params, headers=headers)

    target = response.json()

    print(target[0][0]["tgt"])

if __name__ == "__main__":
    translate()
1 Like

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.

Regards,
Kishor.

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.

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

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,
Kishor.

Hi,

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: http://opennmt.net/OpenNMT/

Hi Panos,

Thank you very much for the support here.

Regards,
Kishor.

Hi ,

I would be using the Docker image. When I run the command
sudo docker run -it opennmt/opennmt:latest
I get the status :
Status : Downloaded newer image for opennmt/opennmt:latest

how do I use this downloaded image as a server .

Could you please assist here.

Thank you,
Kishor.