Stay organized with collectionsSave and categorize content based on your preferences.
Translate text by using adaptive translation
When you request an adaptive translation, you provide the text to translate and
example translations that Cloud Translation uses to tailor its responses.
For programmatic translation requests, you can include example translations in a
dataset or as part of your translation request. When you use a dataset,
Cloud Translation automatically selects five reference sentences that are
most similar to your source sentence to customize translations. If you include
reference sentences in your translation request, Cloud Translation uses all
of them to customize the translation.
Before you begin
To use adaptive translation, you must enable the Cloud Translation API in your
project and set up authentication. For more information, see the
Cloud TranslationSetup.
Also, check that your source and targetlanguagesare
supported by adaptive translation.
Data requirements and suggestions
If you create a dataset or use the Google Cloud console, you must provide
example translations in aTSV or TMX file. The examples must be
sentence pairs in your intended source and target languages. We recommend that
you provide examples that cover the vocabulary, usage, and grammatical quirks of
your domain. For additional tips, seeData preparationin the
AutoML Translation documentation.
Your data must include at least 5 sentence pairs and no more than 10,000 pairs
if you use the console and no more than 30,000 pairs if you use the API. A
segment pair can be at most 512 characters (total).
Limitations
You can translate to only one target language at a time.
Adaptive translation has limits on the number of input and output characters.
For more information, see theAdaptive translationlimits
on the Quotas page.
Request translations
For translations, the input can be plain text or HTML. Cloud Translation doesn't
translate any HTML tags in the input, only text that appears between the tags.
The output retains the (untranslated) HTML tags, with the translated text
between the tags to the extent possible due to differences between the source
and target languages.
Console
When using the Google Cloud console, select a file that includes your
example translations and then request translations. Cloud Translation
doesn't store your imported data. If you prefer to work with persistent
datasets, use the API.
Select a local file or a file in Cloud Storage that contains your
example translations.
After you select a file, Cloud Translation sets theSource
languageandTarget languagefields based on your data. For example,
if you import an English to Portuguese dataset, the console lets you
translate only English sentences to Portuguese.
Enter text in the source language field.
Adaptive translation does have limits on the number of input and output
characters. For more information, see theAdaptive
translation limitson the Quotas page.
To adjust parameters, use the sliders or text fields to set values:
Temperature- Controls the degree of randomness in token selection.
For lower temperatures, expect a true or correct response. For higher
temperatures, expect more diverse or unexpected results.
Number of examples- Sets the number of examples to use from your
source data to prompt the LLM.
SelectCompare with NMT modelto include translations from the default
Google NMT model along with the adaptive translation output.
ClickTranslate.
In a few moments, Cloud Translation returns a response in the target
language field. Cloud Translation doesn't return any text beyond the
output character limit.
API
Use the API to request adaptive translations by including reference sentence
pairs or by specifying a dataset.
Adaptive translations with reference sentence pairs
To include example translations as part of your translation requests, include
your example source and target sentence pairs in thereferenceSentencePairsfield, which is part of thereferenceSentenceConfigobject. For more
information, see theadaptiveMtTranslatemethod.
You can include up to five sentence pairs.
REST
Before using any of the request data,
make the following replacements:
PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of
your Google Cloud project
LOCATION: The region where your translation request is handled,
such asus-central1.
REFERENCE_SOURCE: A sentence in the source language that is
part of a reference sentence pair.
REFERENCE_TARGET: A sentence in the target language that is
part of a reference sentence pair.
SOURCE_LANGUAGE: Thelanguage codeof the source text.
TARGET_LANGUAGE: Thelanguage codeof
the language to translate the source text to.
SOURCE_TEXT: The text to translate.
MIME_TYPE(Optional): The format of the source text, such astext/htmlortext/plain. By default, the MIME type
is set totext/plain.
HTTP method and URL:
POST https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION:adaptiveMtTranslate
/** Translates using AdaptiveMt. */privatestaticvoidadaptiveMtTranslate(TranslationServiceClienttranslationServiceClient,StringprojectId,StringsourceLang,StringtargetLang,Pair<String,String>referencePairs){ReferenceSentencePairListrefList=ReferenceSentencePairList.newBuilder();for(Pair<String,String>referencePair:referencePairs){ReferenceSentencePairrefPair=ReferenceSentencePair.newBuilder().setSourceSentence(referencePair.getKey()).setTargetSentence(referencePair.getValue());refList.addReferenceSentencePair(refPair);}AdaptiveMtTranslateRequestrequest=AdaptiveMtTranslateRequest.newBuilder().setParent(LocationName.of(projectId,"us-central1").toString()).setSourceLanguageCode(sourceLang).setTargetLanguageCOde(targetLang).addReferenceSentencePairLists(refList).build();AdaptiveMtTranslateResponseresponse=translationServiceClient.adaptiveMtTranslate(request);System.out.println("Translating using AdaptiveMt");System.out.println(response);}
defadaptive_mt_translate():# Create a clientclient=translate.TranslationServiceClient()# Initialize the requestrequest=translate.AdaptiveMtTranslateRequest(parent="projects/PROJECT_ID/locations/LOCATION",reference_sentence_config=["reference_sentence_pair_lists":["reference_sentence_pairs":{"source_sentence":'REFERENCE_SOURCE_1_1'"target_sentence":'REFERENCE_TARGET_1_1'},"reference_sentence_pairs":{"source_sentence":'REFERENCE_SOURCE_1_2'"target_sentence":'REFERENCE_TARGET_1_2'}],"source_language_code":'SOURCE_LANGUAGE'"target_language_code":'TARGET_LANGUAGE'],content=["SOURCE_TEXT"])# Make the requestresponse=client.adaptive_mt_translate(request)# Handle the responseprint(response)
Adaptive translations with a dataset
To use a dataset with translations, create a dataset and import sentence
pairs first. If you already have a dataset, you can request adaptive
translations with it. The dataset persists in your project until you delete
it.
Create a dataset where you import your example translations.
The source and targetlanguagesmust match the
languages that you intend to use in your translations. For more
information, see theadaptiveMtDataset.createmethod.
REST
Before using any of the request data,
make the following replacements:
PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of
your Google Cloud project
LOCATION: The region where your source dataset is located, such
asus-central1.
DATASET_ID: A unique identifier for your dataset.
DISPLAY_NAME: A descriptive name for your dataset.
SOURCE_LANGUAGE: The language code of the input text. For
supported language codes, seeSupported
languages.
TARGET_LANGUAGE: The target language to translate the input
text to. For supported language codes, seeSupported
languages.
HTTP method and URL:
POST https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets
asyncfunctioncreateAdaptiveMtDataset(){// Construct requestconstrequest={parent:`projects/${projectId}/locations/${location}`,adaptiveMtDataset:{name:`projects/${projectId}/locations/${location}/adaptiveMtDatasets/${adaptiveMtDatasetName}`,displayName:'DATASET_DISPLAY_NAME',sourceLanguageCode:'SOURCE_LANGUAGE_CODE',targetLanguageCode:'TARGET_LANGUAGE_CODE',}};// Run requestconst[response]=awaittranslationClient.createAdaptiveMtDataset(request);console.log('Created')console.log(response)}
defcreate_adaptive_mt_dataset():# Create a clientclient=translate.TranslationServiceClient()# Initialize request argument(s)adaptive_mt_dataset=translate.AdaptiveMtDataset()adaptive_mt_dataset.name="projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID"adaptive_mt_dataset.display_name="DATASET_DISPLAY_NAME"adaptive_mt_dataset.source_language_code="SOURCE_LANGUAGE_CODE"adaptive_mt_dataset.target_language_code="TARGET_LANGUAGE_CODE"request=translate.CreateAdaptiveMtDatasetRequest(parent="projects/PROJECT_ID/locations/LOCATION",adaptive_mt_dataset=adaptive_mt_dataset,)# Make the requestresponse=client.create_adaptive_mt_dataset(request=request)# Handle the responseprint(response)
After you create a dataset, populate it with example translations from a
TSV or TMX file.
defimport_adaptive_mt_file():# Create a clientclient=translate.TranslationServiceClient()gcs_input_source=translate.GcsInputSource()gcs_input_source.input_uri="gs://SOURCE_LOCATION/FILE.tsv"# Initialize the requestrequest=translate.ImportAdaptiveMtFileRequest(parent="projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID",gcs_input_source=gcs_input_source)# Make the requestresponse=client.import_adaptive_mt_file(request)# Handle the responseprint(response)
Request an adaptive translation by providing the source text to translate
and the dataset that Cloud Translation uses to customize the
translation.
Cloud Translation uses the source and target language from the
dataset to determine which languages to use for your translation. For
example, anentoesdataset translates
text from English to Spanish. For more information, see theadaptiveMtTranslatemethod.
REST
Before using any of the request data,
make the following replacements:
PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of
your Google Cloud project
LOCATION: The region where your source dataset is located, such
asus-central1.
DATASET_NAME: The name of the dataset that
Cloud Translation uses to customize your translations, formatted asprojects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID.
You can get dataset names bylisting
all datasetsin your project.
SOURCE_TEXT: The text to translate.
MIME_TYPE(Optional): The format of the source text, such astext/htmlortext/plain. By default, the MIME type
is set totext/plain.
HTTP method and URL:
POST https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION:adaptiveMtTranslate
/** Translates using AdaptiveMt. */privatestaticvoidadaptiveMtTranslate(TranslationServiceClienttranslationServiceClient,StringprojectId,StringdatasetId){StringadaptiveMtDatasetName=String.format("projects/%s/locations/LOCATION/adaptiveMtDatasets/%s",projectId,datasetId);AdaptiveMtTranslateRequestrequest=AdaptiveMtTranslateRequest.newBuilder().setParent(LocationName.of(projectId,"us-central1").toString()).setDataset(adaptiveMtDatasetName).addContent("Sample translation text").build();AdaptiveMtTranslateResponseresponse=translationServiceClient.adaptiveMtTranslate(request);System.out.println("Translating using AdaptiveMt");System.out.println(response);}
defadaptive_mt_translate():# Create a clientclient=translate.TranslationServiceClient()# Initialize the requestrequest=translate.AdaptiveMtTranslateRequest(parent="projects/PROJECT_ID/locations/LOCATION",dataset="projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID",content=["Sample translation request"])# Make the requestresponse=client.adaptive_mt_translate(request)# Handle the responseprint(response)
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,[]]