AI_TRANSLATE is a MaxCompute AI function that calls a model to translate input text and returns the translated text.
Syntax
STRING AI_TRANSLATE(
STRING <model_name>,
STRING <version_name>,
STRING <input>,
STRING <target_language>
[, STRING <model_parameters>]
);Parameters
model_name: Required. A value of the STRING type. Specifies the name of the model to use. For more information, see SQL AI functions.
version_name: Required. A value of the STRING type. Specifies the version of the model to use. To call the default version, you can use
DEFAULT_VERSION.input: Required. A string containing the text to be translated.
target_language: Required. A string specifying the target language for the translation, formatted as an ISO-639 language code. Supported language codes include:
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. A string specifying model parameters in JSON format, such as max_tokens, temperature, and top_p. For example:
'{"max_tokens": 500, "temperature": 0.6, "top_p": 0.95}'.-
max_tokens: The maximum number of tokens to generate in a single model call. The default for MaxCompute public models is 4096.
-
temperature: A value between 0 and 1 that controls the randomness of the model's output. A higher value results in more creative and diverse output, while a lower value makes the output more deterministic and conservative.
-
top_p: A value between 0 and 1 that limits the range of candidate labels the model considers. A higher value results in a wider range and more diversity, while a lower value results in a narrower range and more focused output.
-
Return value
Returns a STRING containing the translated text. The return rules are as follows:
The function returns an error if
inputortarget_languageis not aSTRING.
Examples
Example 1: Translate text to a specified language
Calls the public model qwen3-max provided by MaxCompute to translate an English sentence into Chinese.
-- Use the model computing service in SQL jobs
SET odps.task.major.version=sql_modelstudio;
SET odps.namespace.schema=true;
SELECT AI_TRANSLATE(
bigdata_public_modelset.default.`qwen3-max`,
DEFAULT_VERSION,
'MaxCompute是一个快速且完全托管的大规模数据仓储计算平台。',
'en'
) AS translated_text;
-- Result
+-----------------+
| translated_text |
+-----------------+
| MaxCompute is a fast, fully managed, large-scale data warehousing and computing platform. |
+-----------------+Example 2: Translate table data into multiple languages
Calls the public model Qwen3-4B-GGUF 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.sql.ai.treat.as.common.model=true;
SET odps.namespace.schema=true;
SELECT
source_text,
lang,
AI_TRANSLATE(
bigdata_public_modelset.default.`Qwen3-4B-GGUF`,
DEFAULT_VERSION,
source_text,
lang
) AS translated_text
FROM translation_tasks;
-- Result
+-----------------------------+------+-------------------------------+
| source_text | lang | translated_text |
+-----------------------------+------+-------------------------------+
| Welcome to Alibaba Cloud. | zh | 欢迎来到阿里云。 |
| Welcome to Alibaba Cloud. | ja | アリババクラウドへようこそ。 |
| Welcome to Alibaba Cloud. | fr | Bienvenue sur Alibaba Cloud. |
| Welcome to Alibaba Cloud. | es | Bienvenido a Alibaba Cloud. |
+-----------------------------+------+-------------------------------+