Package: interpres
Interpres (Translator)Latin Nouninterpresmorf(genitive interpretis); third declensionAn agent between two parties;broker,negotiator,factor.Synonyms:cōciō,arillātorA translator,interpreter,expounder,expositor,explainer;dragoman.Synonyms:coniector,commentātor,interpretātor,trānslātorTranslatefromone languagetoanother,anysentenceyou would like.# Translate [FROM] [TO] [SENTENCES]❯translatefr"Traduisez quelle que soit la phrase que vous voulez."Translatewhateversentenceyouwant.Uses Meta's NLLB modelfacebook/nllb-200-distilled-600Mby default. You can change it by passing a custom flag--model_id.InstallationUsepipto install Translator.❯pipinstallinterpresOr from source.❯pipinstallgit+https://github.com/wasertech/Translator.gitYou can also use a specific version.❯pipinstallinterpres==0.3.1b4
❯pipinstallgit+https://github.com/wasertech/Translator.git@v0.3.1b4Locate Translator.❯whichtranslateUsageUsingtranslatefrom your favorite shell.❯translatehelpusage:translate[-h][-v][-dDIRECTORY][-SSAVE][-lMAX_LENGTH][-mMODEL_ID][-pPIPELINE][-bBATCH_SIZE][-nNPROC][-eNEPOCH][-L][_from][_to][sentences...]Translate[FROMonelanguage][TOanother],[anySENTENCEyouwouldlike].

positionalarguments:_fromSourcelanguagetotranslatefrom._toTargetlanguagetotranslatetowards.sentencesSentencestotranslate.

options:-h,--helpshowthishelpmessageandexit-v,--versionshowsthecurrentversionoftranslator-dDIRECTORY,--directoryDIRECTORYPathtodirectorytotranslateinbatchinsteadofuniquesentence.-SSAVE,--saveSAVEPathtotextfiletosavetranslations.-lMAX_LENGTH,--max_lengthMAX_LENGTHMaxlengthofoutput.-mMODEL_ID,--model_idMODEL_IDHuggingFacemodelIDtouse.-pPIPELINE,--pipelinePIPELINEPipelinetasktouse.-bBATCH_SIZE,--batch_sizeBATCH_SIZENumberofsentencestobatchfortranslation.-nNPROC,--nprocNPROCNumberofprocesstospawnforfilteringuntraslatedsentences.-eNEPOCH,--nepochNEPOCHNumberofepoch(s)totranslatebatchedsentences.-L,--language_listShowlistoflanguages.You cantranslatefromone languagetoanother, anysentenceyou would like.Greet Translator.❯ translate
ℹ Welcome!
ℹ I am Translator version: 0.3.1b5
ℹ At your service.
? What would you like to translate? Manually typed sentences
ℹ Translating from: Manually typed sentences
? What language to translate from? en
ℹ Translating from eng_Latn.
? What language to translate to? fr
ℹ Translating to fra_Latn.
ℹ Preparing to translate...
Type [Ctrl] + [C] to exit.
          
What would you like to translate?
? Translate: This is a prompt-like translation shell!
C'est une coquille de traduction rapide !

What would you like to translate?
? Translate: You can quickly and effortlessly translate anything from here!
Vous pouvez traduire n'importe quoi rapidement et sans effort.

What would you like to translate?
? Translate: I hope you like my work and are considering becoming a sponsor...
J'espère que vous aimez mon travail et que vous envisagez devenir sponsor...

What would you like to translate?
? Translate:                                                                                                                                                                                 

Cancelled by userGet Translator version.❯translateversionTranslate from English in French.❯ translate eng_Latn fra_Latn "This is French."
C'est français.

❯ LANG="fr_CH.UTF-8" translate en "This is also French."
C'est aussi français.Translate from English in Spanish.❯translateeng_Latnspa_Latn"This is Spanish."Estoesespañol.

❯translateenes"This is also Spanish."Estotambiénesespañol.You can also easilytranslatefiles from a--directoryand--saveto a file.❯translate--directory.--saveen2fr.txteng_Latnfra_Latn-n24-e1000-b64Define:--nepoch (-e)as small as possible but as big as necessary.Translator uses this numbereof epoch to determine
the rate of time between updates
by the amount of sentences
given for translation at once.If this number is too small, you will face Out-Of-Memory (OOM) errors.
If it is too big, you will get poor efficency.Keep it between 1 and the sum of sentences to translate.For maximum efficency keep it as low as you can while beeing able
to fitepoch_splitnumber of sentences
intodevice's memory.--batch_size (-b)as big as possible but as small as necessary.Translator uses this value every time it needs to batch sentences to work on them.Mostly impacts the amount of sentences to batch togheter fromepoch_splitsentences to translate in one go.Keep it as high as possible (<epoch_split) but as low as yourdevicememory allows to (<=1).For GPU using multiples of2is best for memory optimization
(i.e.2,4,8,16,32,64,128,256,512, etc.).--nproc (-n)to equal your amount of virtual threads on CPU for maximum performance.This value is used by translator everytime multiples sentences need to be processed by the CPU.Keeping it at its highest possible value,
garanties maximum performances.With a good processor and a single fast and large GPU,
you can translate an average just shy of a 100 sentences per second.On my Threadripper 2920X's 24 threads,
using my RTX 3060's 12 Gb of space,
I can peak at ~97 translations/second averaging a bit lower at 83.I have not tested yet on my two RTX Titans but if you want to distribute the computation, you'll have to do it manually for now.
It's in my todo list but I won't be offended if you send me a pull request to implement it.UsingTranslatorwithpython.fromtranslatorimportTranslatortranslator=Translator("eng_Latn","fra_Latn")english_sentence="This is just a simple phrase."or["Those are multiples sentences.","If you have lots of them, load them directly from file.","To efficiently batch translate them."]french_sentence=translator.translate(english_sentence)print(f"{english_sentence=}")print(f"{french_sentence=}")LanguagesDepending on models used, you might get fewer choices
but withNLLByou get more than 200 most popular ones.# translate -L❯translate--language_list
Languagelist:...Frompython:>>>importtranslator>>>len(translator.LANGS)202>>>translator.LANGS['ace_Arab','...','zul_Latn']>>>fromtranslator.languageimportget_nllb_lang,get_sys_lang_format>>>nllb_lang=get_nllb_lang("en")>>>nllb_lang'eng_Latn'>>>get_sys_lang_format()'fra_Latn'CheckoutLANGSto see the full list of supported languages.Using a custom modelCheckoutHuggingFace Zoo of Translation Models.Ortrain your own modelfor thetranslateortranslate_xx_to_xxpipeline.LicenseThis project is distributed underMozilla Public License 2.0.Using this tool to translate a sentence,
the licence of the original sentence still applies unless specified otherwise.Meaning,
if you translate a sentence
underCreative Commons CC0,
the translation is also under Creative Commons CC0.Idem for any licence.ContributionI love stars ⭐
but also chocolate 🍫
so don't hesitate
tosponsor this project!Otherwise
if you like the project
and want to see it grow,
get more convenience features
like a dedicated service/client
to speed up multiple translations,
etc.Don't hesitate to share your ideas
by opening a ticket
or even proposing a pull request.