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

0 Likes

(Panos Kanavos) #2

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

(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.

Regards,
Kishor.

0 Likes

(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.

0 Likes

(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…

0 Likes

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

0 Likes

(Panos Kanavos) #7

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/

0 Likes

(Kishor Kp) #8

Hi Panos,

Thank you very much for the support here.

Regards,
Kishor.

0 Likes

(Kishor Kp) #9

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.

0 Likes