TenshiTranslator.Translator.BatchTranslator module¶
- class TenshiTranslator.Translator.BatchTranslator.BatchTranslator(outputOption: OutputFormat, preprocessGlossary: Glossary, postProcessGlossary: Glossary, sugoiDirectory: str, batchSize: int = 64)¶
Bases:
Translator
Translator that send batches to sugoi toolkit’s offline translation server.
Files are translated in batches through http requests, optimizating translation time by maximizing GPU utilization. This translator requires sugoi toolkit and a Nvidia GPU to be useful, but is magnitudes faster than the other translators. You will have to install CUDA and run the setup script to allow the sugoi toolkit to accept batch translation requests. This translator is recommended if you have an Nvidia GPU. The object takes around 12 seconds to initialize, as it starts the sugoi offline translator server.
- Parameters:
outputOption – the output format to use
preprocessGlossary – the glossary to use for preprocessing
postProcessGlossary – the glossary to use for postprocessing
sugoiDirectory – the path to the sugoi toolkit
batchSize – the number of lines to translate per request, defaults to 64
- sendTranslationRequest(batch: list[str]) list[str] ¶
Translates a batch from japanese to english using the sugoi offline translator server
- Parameters:
batch – list of japanese lines to be translated
- Returns:
the translated batch
- translate(inputFilePath: str)¶
Translates a file and writes to inputFilePath-Translated.txt
- Parameters:
inputFilePath – path to the file to be translated
- Raises:
FileNotFoundError if the file is not found
- Raises:
Exception if any other error occurs