##
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

- 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

Language

Client

Provider

Settings

    import os
    from huggingface_hub import InferenceClient

    client = InferenceClient(
        provider="hf-inference",
        api_key=os.environ["HF_TOKEN"],
    )

    result = client.translation(
        "Меня зовут Вольфганг и я живу в Берлине",
        model="google/madlad400-3b-mt",
    )

###
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.

Update on GitHub