AI_TRANSLATE is a MaxCompute AI function that calls a model to translate input text into a specified language.
Syntax
STRING AI_TRANSLATE(
STRING <model_name>,
STRING <version_name>,
STRING <input>,
STRING <target_language>
[, STRING <model_parameters>]
);Parameters
model_name: Required. STRING. The name of the model to use. For more information, see SQL AI functions.
version_name: Required. STRING. The version of the model to use. To call the default version, enter
DEFAULT_VERSION.input: Required. STRING. The text to translate.
target_language: Required. STRING. The target language for the translation, specified as an ISO-639 language code. The following language codes are supported:
Language code
Language
zh
Chinese
en
English
es
Spanish
fr
French
de
German
ja
Japanese
ko
Korean
ru
Russian
ar
Arabic
pt
Portuguese
model_parameters: Optional. STRING. Specifies model parameters such as
max_tokens,temperature, andtop_p. The format is a JSON string:'{"max_tokens": 500, "temperature": 0.6, "top_p": 0.95}'.max_tokens: The maximum number of tokens to generate in a single model call. For MaxCompute public models, the default value is 4,096.
temperature: A value between 0 and 1 that controls the randomness of the output. A higher value results in more creative and diverse output, while a lower value produces more deterministic and conservative output.
top_p: A value between 0 and 1 that limits the range of candidate labels the model can choose from. A higher value allows for a broader range and more diversity, while a lower value narrows the range and produces more focused results.
Return value
Returns the translated text as a STRING value.
If the input or target_language parameter is not a STRING, an error is returned.
Examples
Example 1: Translate text into a specified language
Calls the qwen3.7-max public model provided by MaxCompute to translate an English sentence into Chinese.
SET odps.namespace.schema=true;
SELECT AI_TRANSLATE(
bigdata_public_modelset.default.`qwen3.7-max`,
DEFAULT_VERSION,
'MaxCompute is a fast and fully managed computing platform for large-scale data warehousing.',
'zh'
) AS translated_text;
-- Result
+-------------------------------------------------------------------------------------------+
| translated_text |
+-------------------------------------------------------------------------------------------+
| MaxCompute is a fast and fully managed computing platform for large-scale data warehousing. |
+-------------------------------------------------------------------------------------------+Example 2: Translate table data into multiple languages
Calls the deepseek-v4-pro public model provided by MaxCompute to translate the same English text into Chinese, Japanese, French, and Spanish in a single query.
-- Sample data
CREATE TABLE translation_tasks (
source_text STRING,
lang STRING
);
INSERT INTO translation_tasks VALUES
('Welcome to Alibaba Cloud.', 'zh'),
('Welcome to Alibaba Cloud.', 'ja'),
('Welcome to Alibaba Cloud.', 'fr'),
('Welcome to Alibaba Cloud.', 'es');
-- Translate the same text into multiple target languages
SET odps.namespace.schema=true;
SELECT
source_text,
lang,
AI_TRANSLATE(
bigdata_public_modelset.default.`deepseek-v4-pro`,
DEFAULT_VERSION,
source_text,
lang
) AS translated_text
FROM translation_tasks;
-- Results
+-----------------------------+------+-------------------------------+
| source_text | lang | translated_text |
+-----------------------------+------+-------------------------------+
| Welcome to Alibaba Cloud. | zh | Welcome to Alibaba Cloud. |
| Welcome to Alibaba Cloud. | ja | アリババクラウドへようこそ。 |
| Welcome to Alibaba Cloud. | fr | Bienvenue sur Alibaba Cloud. |
| Welcome to Alibaba Cloud. | es | Bienvenido a Alibaba Cloud. |
+-----------------------------+------+-------------------------------+FAQ
Troubleshoot common issues with public models
Symptom: When you call a public model that is supported by the model computing service, the following error message is returned.
FAILED: ODPS-0130071:[1,8] Semantic analysis exception - inference quota status check failed, error message: region cn-shanghai not found in inference quotaCause: The model computing service is not enabled for the region, such as China (Shanghai), where your current project is located. As a result, AI inference resources cannot be called.
Solution: Go to the Alibaba Cloud Management Console to enable the model computing service for the region where your project is located. For more information, see Purchase and use the MaxCompute model computing service.