Skip to main content

Command Palette

Search for a command to run...

Tips for faster translation using Argos Translate Python

Published
2 min read

About Argos Translate

Argos Translate is an open-source, cross-platform language translation software developed by the Argos Open Technologies, LLC. The software uses 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:

import argostranslate.package
import argostranslate.translate

from_code = "en"
to_code = "es"

# Download and install Argos Translate package
argostranslate.package.update_package_index()
available_packages = argostranslate.package.get_available_packages()
package_to_install = next(
    filter(
        lambda x: x.from_code == from_code and x.to_code == to_code, available_packages
    )
)
argostranslate.package.install_from_path(package_to_install.download())

# Translate
translatedText = argostranslate.translate.translate("Hello World", from_code, to_code)
print(translatedText)
# '¡Hola Mundo!'

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

import argostranslate.package
import argostranslate.translate
from argostranslate.translate import translate, get_installed_languages

from_code = "en"
to_code = "es"

en, es = get_installed_languages() # [LanguageModel_English, LanguageModel_Spanish]
translator = es.get_translation(en)

# use only this part in loop
translatedText = translator.translate(text)

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.

Why isn't it the default method?

Well from what I can read from the docs it appears the developer is working on making it available. There are methods described in code that can do what I wrote but it is not implemented yet.

Thank you.

J

This post on tips for faster translation is incredibly informative! Speed and efficiency are crucial in the translation process, especially when dealing with large volumes of content. Argos Translate is a powerful tool to streamline translation tasks, and it's great to see how Python can be leveraged to optimize the process further. For businesses and individuals seeking professional translation services, partnering with a trusted translation agency can complement these efforts. A proficient translation agency can offer a team of skilled linguists and advanced translation tools, ensuring accurate and timely translations for various languages. Combining Argos Translate's efficiency with a translation agency's expertise can result in a winning combination for high-quality and speedy translations. Kudos to the author for sharing these helpful tips and promoting the importance of efficient translation processes!

More from this blog

Holomorphic Guy

7 posts