Inference Providers documentation
Translation
Translation
Translation is the task of converting text from one language to another.
For more details about the translation
task, check out its dedicated page! You will find examples and related materials.
Recommended models
- facebook/nllb-200-1.3B: Very powerful model that can translate many languages between each other, especially low-resource languages.
- google-t5/t5-base: A general-purpose Transformer that can be used to translate from English to German, French, or Romanian.
Explore all available models and find the one that suits you best here.
Using the API
Copied
from huggingface_hub import InferenceClient
client = InferenceClient(
provider="hf-inference",
api_key="hf_xxxxxxxxxxxxxxxxxxxxxxxx",
)
result = client.translation(
inputs="Меня зовут Вольфганг и я живу в Берлине",
model="facebook/nllb-200-distilled-600M",
)
API specification
Request
Headers | ||
---|---|---|
authorization | string | Authentication header in the form 'Bearer: hf_****' when hf_**** is a personal user access token with “Inference Providers” permission. You can generate one from your settings page. |
Payload | ||
---|---|---|
inputs* | string | The text to translate. |
parameters | object | |
src_lang | string | The source language of the text. Required for models that can translate from multiple languages. |
tgt_lang | string | Target language to translate to. Required for models that can translate to multiple languages. |
clean_up_tokenization_spaces | boolean | Whether to clean up the potential extra spaces in the text output. |
truncation | enum | Possible values: do_not_truncate, longest_first, only_first, only_second. |
generate_parameters | object | Additional parametrization of the text generation algorithm. |
Response
Body | ||
---|---|---|
translation_text | string | The translated text. |