Model:
POST https://api.textsynth.com/v1/engines/{engine_id}/translate
where engine_id is the
selected engine.
text: array of strings.
Each string is an independent text to translate. Batches of at most 64 texts can be provided.
source_lang: string.
Two or three
character ISO
language code for the source language. The special
value "auto" indicates to auto-detect the source
language. The language auto-detection does not support all
languages and is based on heuristics. Hence if you know the
source language you should explicitly indicate it.
target_lang: string.
Two or three character ISO language code for the target language.
num_beams: integer (range: 1 to 5, default = 4).
Number of beams used to generate the translated text. The translation is usually better with a larger number of beams. Each beam requires generating a separate translated text, hence the number of generated tokens is multiplied by the number of beams.
split_sentences: optional boolean (default = true).
The translation model only translates one sentence at a
time. Hence the input must be split into sentences. When
split_sentences = true (default), each input text is
automatically split into sentences using source language
specific heuristics.
If you are sure that each input text contains
only one sentence, it is better to disable the automatic
sentence splitting.
translations: array of objects.
Each object has the following properties:
text: string
Translated text
detected_source_lang: string
ISO language code corresponding to the detected lang (identical to source_lang if language auto-detection is not enabled)
input_tokens: integer
Indicate the total number of input tokens. It is useful to estimate the number of compute resources used by the request.
output_tokens: integer
Indicate the total number of generated tokens. It is useful to estimate the number of compute resources used by the request.
curl https://api.textsynth.com/v1/engines/m2m100_1_2B/translate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"text": ["The quick brown fox jumps over the lazy dog."], "source_lang": "en", "target_lang": "fr" }'
Answer:
{
"translations": [{"detected_source_lang":"en","text":"Le renard brun rapide saute sur le chien paresseux."}],
"input_tokens": 18,
"output_tokens": 85
}
Python example: translate.py