Tips for faster translation using Argos-Translate Python

Has
1 min readJan 20, 2023

--

About Argos Translate

Argos Translate is an offline language translator that uses TensorFlow for translations and can be used as either a Python library, command-line, or GUI application.

Installation

Simply run the following command in your environment

pip install argostranslate

Usage

A typical first run code like this:

This API is simple and it automatically downloads the necessary files for translation. However, it’s impractical to use it in this form in a web service or a public application because this API is too redundant and takes a lot of time.

Faster Translation in a Loop

Explanation

Line 1–3 : import necessary packages, it can be simplified.

Line 5–6: Selects translation languages. In arrow representation this would be en->es or English → Spanish

Line 8: Get a list of installed languages. These languages are installed using the code given in the earlier section. In this case I installed only these two languages so I am unpacking them int `vars`.

Line 9: Load the translation model in memory.

Line 12: Since everything is saved in memory already, if this line is used in for loop it would not take as much time as earlier code.

So Why is it faster?

Well, when using the argostranslate.translate.translate the module first performs a few filters and not to mention it reloads the language model on every call so it is inefficient.

Thank you.

--

--

Responses (1)