Translation LLM (TLLM) model

Google's latest state-of-the-art translation model, TLLM, is a LoRA-tuned LLM that provides the highest available quality of translation. It achieves significantly better MetricX and COMET scores on difficult workloads than other translation models. It supports customization as well as more lightweight Adaptive Translation .

Its model ID is general/translation-llm .

To access the TLLM model, you need to have a Google Cloud project that has Cloud Translation - Advanced API enabled, with credentials to make authenticated calls. To access the model using Python or another programming language, install the appropriate v3 client library .

In the examples presented here, PROJECT_ID represents your project ID, and REGION_NAME represents the technical region name of the Google Cloud region where you want to run the translation operation (such as us-central1 ). Use ISO-639 codes to identify source and target languages where necessary.

Text translation REST example

You can use the REST API to call TranslateText on the TLLM model. You can put request fields into a JSON file named something like request.json :

 {
  "contents": ["This is text that I would like to have translated.",
               "It can include up to 1024 strings."],
  "mimeType": "text/plain",
  "sourceLanguageCode": "en"
  "targetLanguageCode": "it",
  "model": "projects/PROJECT_ID/locations/REGION_NAME/models/general/translation-llm"
} 

You can then use a curl command to submit the request:

 curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "x-goog-user-project: PROJECT_ID" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://translation.googleapis.com/v3/projects/PROJECT_ID:translateText" 

The response is a JSON document that looks like this:

  { 
  
 "translations" 
 : 
  
 [ 
  
 { 
  
 "translatedText" 
 : 
  
 "Este es el texto que me gustaría traducir." 
 , 
  
 "model" 
 : 
  
 "projects/PROJECT_ID/locations/REGION_NAME/models/general/translation-llm" 
  
 }, 
  
 { 
  
 "translatedText" 
 : 
  
 "Puede incluir hasta 1024 cadenas." 
 , 
  
 "model" 
 : 
  
 "projects/PROJECT_ID/locations/REGION_NAME/models/general/translation-llm" 
  
 } 
  
 ] 
 } 
 

Text translation Python example

Here is sample Python code for calling TranslateText with the TLLM model:

  from 
  
 google.cloud 
  
 import 
  translate 
 
_v3 def 
  
 translate 
 (): 
 response 
 = 
 translate_v3 
 . 
  TranslationServiceClient 
 
 () 
 . 
 translate_text 
 ( 
 contents 
 = 
 [ 
 "Life is short." 
 , 
 "Art is long." 
 ], 
 target_language_code 
 = 
 'fr' 
 , 
 source_language_code 
 = 
 'en' 
 , 
 parent 
 = 
 f 
 "projects/PROJECT_ID/locations/REGION_NAME" 
 , 
 model 
 = 
 f 
 "projects/PROJECT_ID/locations/REGION_NAME/models/general/translation-llm" 
 ) 
 print 
 ( 
 response 
 ) 
 return 
 response 
 translate 
 () 
 

The response takes the form of JSON objects:

  translat 
 io 
 ns 
  
 { 
  
 translate 
 d_ 
 te 
 x 
 t 
 : 
  
 "La vie est courte." 
  
 model 
 : 
  
 "projects/261347268520/locations/us-central1/models/general/translation-llm" 
 } 
 translat 
 io 
 ns 
  
 { 
  
 translate 
 d_ 
 te 
 x 
 t 
 : 
  
 "L'art est long." 
  
 model 
 : 
  
 "projects/261347268520/locations/us-central1/models/general/translation-llm" 
 } 
 translat 
 io 
 ns 
  
 { 
  
 translate 
 d_ 
 te 
 x 
 t 
 : 
  
 "La vie est courte." 
  
 model 
 : 
  
 "projects/261347268520/locations/us-central1/models/general/translation-llm" 
 } 
 translat 
 io 
 ns 
  
 { 
  
 translate 
 d_ 
 te 
 x 
 t 
 : 
  
 "L'art est long." 
  
 model 
 : 
  
 "projects/261347268520/locations/us-central1/models/general/translation-llm" 
 
Design a Mobile Site
View Site in Mobile | Classic
Share by: