This topic describes the main APIs for the custom translation service of the Machine Translation Self-learning Platform.
1. Custom model call API
Request URL: [http|https]://automl.cn-hangzhou.aliyuncs.com/api/automl/predict.
You can call the PredictMTModel API operation over RPC to obtain results from the machine translation self-learning model.
1.1 Input parameters
Parameter | Required | Type | Description |
ModelId | Yes | Long | The model ID. |
Content | Yes | String | The content to translate. The content can be up to 5,000 bytes in length. |
ModelVersion | No | String | The version number of the model, such as V1 or V2. If you do not specify this parameter, the latest version is used by default. |
1.2 Output parameters
Parameter name | Type | Description |
code | Int32 | The error code. |
message | String | The error message. |
success | Boolean | Is the result correct? |
result | String | The translated text. |
Example
Input:
{
"ModelId": "532",
"Content": "hello",
"ModelVersion": "V1" // You can specify the model version number, such as V1 or V2. If you do not specify this parameter, the latest version is used by default.
}Outputs:
{"Data":["hello"],"RequestId":"fweo1j3931jd","Code":0}Example of calling a custom model using an SDK
An AccessKey of an Alibaba Cloud account has permissions to access all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
Do not save your AccessKey ID and AccessKey secret in your project code. If you save the AccessKey ID and AccessKey secret in your project code, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. This example shows how to use the Alibaba Cloud Credentials tool to manage the AccessKey for API authentication. For more information about how to configure environment variables, see Configure credentials.
package com.alibaba.nlp.automl.modelcenter.service;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
public class PredictDemo {
private void predictModel() {
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Read the access credential from the environment variable.
String regionId = "cn-hangzhou";
try {
// Create and initialize a DefaultAcsClient instance.
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", credentialsProvider);
IAcsClient client = new DefaultAcsClient(profile);
// Create an API request and set the parameters.
CommonRequest request = new CommonRequest();
request.setDomain("automl.cn-hangzhou.aliyuncs.com");
request.setVersion("2019-07-01");
request.setAction("PredictMTModel");
request.setMethod(MethodType.POST);
request.putQueryParameter("ModelId", "647");
request.putQueryParameter("ModelVersion", "V1");
request.putBodyParameter("Content", "hello");
CommonResponse response = client.getCommonResponse(request);
System.out.println(response);
} catch (Exception e) {
e.printStackTrace();
}
}
}2. Intervention API
Request URL: [http|https]://automl.cn-hangzhou.aliyuncs.com/api/automl/addMtIntervenePackage.
You can call the AddMtIntervenePackage API operation over RPC to obtain results from the machine translation self-learning model.
2.1 Input parameters
Parameter name | Required | Type | Description |
PackageName | Yes | String | The name of the term package. |
ProjectId | Yes | Long | The project ID. |
SourceLanguage | Yes | String | The source language (zh, ja, en). |
TargetLanguage | Yes | String | The target language (zh, ja, en). |
2.2 Output parameters
Parameter name | Type | Description |
code | Int32 | The return code. |
message | String | The error message. |
RequestId | String | The request ID. |
PackageId | Long | The term package ID. |
Input:
{
"PackageName": "test",
"ProjectId": "1",
"SourceLanguage": "zh",
"TargetLanguage": "en",
}Outputs:
{
"Code": "200",
"RequestId": "aare83jnn9wj3",
"Message": "",
"PackageId": "1"
}3. Add intervention word API
Request URL: [http|https]://automl.cn-hangzhou.aliyuncs.com/api/automl/addMTInterveneWord.
You can call the AddMTInterveneWord API operation over RPC to obtain results from the machine translation self-learning model.
3.1 Input parameters
Parameter Name | Required | Type | Description |
SourceText | Yes | String | The source text. The text can be up to 1,024 bytes in length. |
TargetText | Yes | String | The intervention text. The text can be up to 1,024 bytes in length. |
PackageId | Yes | Long | The term package ID. |
ProjectId | Yes | Long | The project ID. |
3.2 Output parameters
Parameter name | Type | Description |
code | Int32 | The return code. |
message | String | The error message. |
RequestId | String | The request ID. |
WordId | Long | The word ID. |
Input:
{
"PackageName": "test",
"ProjectId": "1"
}Outputs:
{
"Code": "200",
"RequestId": "aare83jnn9wj3",
"Message": "",
"PackageId": "1"
}4. Bind intervention term package to model API
Request URL: [http|https]://automl.cn-hangzhou.aliyuncs.com/api/automl/bindIntervenePackageAndModel.
You can call the BindIntervenePackageAndModel API operation over RPC to obtain results from the machine translation self-learning model.
4.1 Input parameters
Parameter name | Required | Type | Description |
ModelId | Yes | Long | The model ID. |
ModelVersion | No | String | The model version. If you do not specify this parameter, the latest version is used. |
PackageId | Yes | Long | The term package ID. |
ProjectId | Yes | Long | The project ID. |
4.2 Output parameters
Parameter Name | Type | Description |
code | Int32 | The return code. |
message | String | The error message. |
RequestId | String | The request ID. |
Success | Long | Is the result correct? |
Input:
{
"PackageId": "1",
"ProjectId": "1",
"ModelId": "1",
"ModelVersion": "V1"
}Outputs:
{
"Code": "200",
"RequestId": "aare83jnn9wj3",
"Message": "",
"Success": "true"
}5. Error codes
Error code | Description |
200 | The request was successful. |
10001 | A parameter verification error occurred. |
11009 | The call quota is exceeded. |
13016 | The API call is throttled (default model + user dimension: 10 QPS). |
13017 | Model authentication failed. |
13018 | The model was not found. |
13020 | The model failed to be published. |
19999 | An internal server error occurred. Try again later or contact a customer service representative for assistance. |