This topic describes the main APIs of the custom translation service provided by the Machine Translation Self-learning Platform.
1. Custom model API
Request URL: [http|https]://automl.cn-hangzhou.aliyuncs.com/api/automl/predict.
The PredictMTModel API uses a Remote Procedure Call (RPC) to retrieve translation results from a custom machine translation model.
1.1 Input parameters
Parameter name | Required | Type | Description |
ModelId | Yes | Long | The model ID. |
Content | Yes | String | The content to translate. The maximum length is 5000 bytes. |
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. |
1.2 Response parameters
Parameter name | Type | Description |
code | Int32 | The error code. |
message | String | The error message. |
success | Boolean | Is the result as expected? |
result | String | The translated text. |
Example
Input:
{
"ModelId": "532",
"Content": "hello",
"ModelVersion": "V1" // The version number of the model, such as V1 or V2. If you do not specify this parameter, the latest version is used.
}
Outputs:
{"Data":["hello"],"RequestId":"fweo1j3931jd","Code":0}
Example of an SDK call for a custom model
An Alibaba Cloud account AccessKey has permissions to access all APIs. We recommend that you use a Resource Access Management (RAM) user for API access or daily O&M.
Do not save the AccessKey ID and AccessKey secret in your project code. If you do, the AccessKey pair may be leaked, which threatens the security of all resources in your account. This example shows how to use the Alibaba Cloud Credentials tool to manage the AccessKey for identity verification. For more information about how to configure and use environment variables, see https://help.aliyun.com/document_detail/378659.html.
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 access credentials from environment variables.
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.
The AddMtIntervenePackage operation retrieves the output of a self-learning machine translation model over RPC.
2.1 Input parameters
Parameter name | Required | Type | Description |
PackageName | Yes | String | The name of the glossary package. |
ProjectId | Yes | Long | The project ID. |
SourceLanguage | Yes | String | The source language. Valid values: zh, ja, en. |
TargetLanguage | Yes | String | The target language. Valid values: zh, ja, en. |
2.2 Response parameters
Parameter name | Type | Description |
code | Int32 | The return code. |
message | String | The error message. |
RequestId | String | The request ID. |
PackageId | Long | The ID of the glossary package. |
Input:
{
"PackageName": "test",
"ProjectId": "1",
"SourceLanguage": "zh",
"TargetLanguage": "en",
}
Outputs:
{
"Code": "200",
"RequestId": "aare83jnn9wj3",
"Message": "",
"PackageId": "1"
}
3. API for adding intervention words
Request URL: [http|https]://automl.cn-hangzhou.aliyuncs.com/api/automl/addMTInterveneWord.
The AddMTInterveneWord API retrieves results from the machine translation self-learning model by making a Remote Procedure Call (RPC).
3.1 Input parameters
Parameter name | Required | Type | Description |
SourceText | Yes | String | The source text. The maximum length is 1024 bytes. |
TargetText | Yes | String | The intervention text. The maximum length is 1024 bytes. |
PackageId | Yes | Long | The ID of the glossary package. |
ProjectId | Yes | Long | The project ID. |
3.2 Response 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. API for attaching a glossary package to a model
Request URL: [http|https]://automl.cn-hangzhou.aliyuncs.com/api/automl/bindIntervenePackageAndModel.
The BindIntervenePackageAndModel API is an RPC API for retrieving results from a self-learning machine translation 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 ID of the glossary package. |
ProjectId | Yes | Long | The project ID. |
4.2 Response 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 as expected? |
Input:
{
"PackageId": "1",
"ProjectId": "1",
"ModelId": "1",
"ModelVersion": "V1"
}
Outputs:
{
"Code": "200",
"RequestId": "aare83jnn9wj3",
"Message": "",
"Success": "true"
}
4. Error codes
Error code | Description |
200 | The request was successful. |
10001 | Parameter verification failed. |
11009 | The call quota is exceeded. |
13016 | The API call is throttled. The default limit is 10 queries per second (QPS) per user for the default model. |
13017 | Model authentication failed. |
13018 | The model was not found. |
13020 | The model was not published successfully. |
19999 | An internal server error occurred. Try again later or contact a customer service representative for assistance. |