Manage datasets
Manage existing adaptive translation datasets by using the Cloud Translation API. You can list datasets, list files that are used by a dataset, delete all entries from a given file, or delete datasets.
List datasets
View a list of all existing adaptive translation datasets in your project.
REST
Before using any of the request data, make the following replacements:
- PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of your Google Cloud project
- LOCATION: The region where your source dataset is located, such
as
us-central1.
HTTP method and URL:
GET https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER_OR_ID" \
"https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets"
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{
"adaptiveMtDatasets": [
{
"name": "projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID",
"displayName": "DISPLAY_NAME",
"sourceLanguageCode": "SOURCE_LANGUAGE",
"targetLanguageCode": "TARGET_LANGUAGE"
}
]
}
Before trying this sample, follow the Java setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Java API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Java
/** Lists all AdaptiveMtDatasets in a project. */
privatestaticvoidlistAdaptiveMtDatasets(
TranslationServiceClienttranslationServiceClient,StringprojectId){
ListAdaptiveMtDatasetsRequestlistAdaptiveMtDatasetsRequest=
ListAdaptiveMtDatasetsRequest.newBuilder()
.setParent(LocationName.of(projectId,"LOCATION").toString())
.build();
ListAdaptiveMtDatasetsPagedResponseresponse=
translationServiceClient.listAdaptiveMtDatasets(listAdaptiveMtDatasetsRequest);
System.out.println("Listing datasets:");
for(AdaptiveMtDatasetdataset:response.iterateAll()){
System.out.println(dataset);
}
}
Before trying this sample, follow the Node.js setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Node.js API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Node.js
asyncfunctionlistAdaptiveMtDatasets(){
constrequest={
parent:`projects/${projectId}/locations/${location}`
}const[response]=awaittranslationClient.listAdaptiveMtDatasets(request)
console.log('Listing datasets')
console.log(response)
}
Before trying this sample, follow the Python setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Python API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Python
deflist_adaptive_mt_datasets():
# Create a client
client = translate.TranslationServiceClient()
# Initialize the request
request = translate.ListAdaptiveMtDatasetsRequest(
parent="projects/PROJECT_ID/locations/LOCATION",
)
# Make the request
response = client.list_adaptive_mt_datasets(request)
# Handle the response
print(response)
List files in dataset
List files in your dataset to view which files were used to populate the dataset. Cloud Translation outputs the file names and the number of sentence pairs (entries) imported from each file.
REST
Before using any of the request data, make the following replacements:
- PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of your Google Cloud project
- LOCATION: The region where your dataset is located, such as
us-central1. - DATASET_ID: The unique identifier of your dataset that contains files to list.
HTTP method and URL:
GET https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID/adaptiveMtFiles
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER_OR_ID" \
"https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID/adaptiveMtFiles"
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID/adaptiveMtFiles" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{
"adaptiveMtFile": [
{
"name": "FILE_NAME",
"displayName": "DESCRIPTIVE_NAME",
"entryCount": TOTAL_ENTRIES
}
]
}
Before trying this sample, follow the Java setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Java API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Java
/** Lists all AdaptiveMtFiles in a dataset. */
privatestaticvoidlistAdaptiveMtFiles(
TranslationServiceClienttranslationServiceClient,StringprojectId,StringdatasetId){
StringadaptiveMtDatasetName=
String.format(
"projects/%s/locations/LOCATION/adaptiveMtDatasets/%s",projectId,datasetId);
TranslationServiceClient.ListAdaptiveMtFilesPagedResponseresponse=
translationServiceClient.listAdaptiveMtFiles(adaptiveMtDatasetName);
System.out.println("Listing dataset files:");
for(AdaptiveMtFilefile:response.iterateAll()){
System.out.println(file.toString());
}
}
Before trying this sample, follow the Node.js setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Node.js API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Node.js
asyncfunctionlistAdaptiveMtFiles(){
constrequest={
parent:`projects/${projectId}/locations/${location}/adaptiveMtDatasets/${
adaptiveMtDatasetName}`,
}const[response]=awaittranslationClient.listAdaptiveMtFiles(request)
console.log('Listing files')
console.log(response)
}
Before trying this sample, follow the Python setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Python API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Python
deflist_adaptive_mt_files():
# Create a client
client = translate.TranslationServiceClient()
# Initialize the request
request = translate.ListAdaptiveMtFilesRequest(
parent="projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID"
)
# Make the request
response = client.list_adaptive_mt_files(request)
# Handle the response
print(response)
Delete dataset file
Delete entries from a particular file for a given dataset. You must provide the file's ID, which is part of the file's resource name that is returned from the list files method.
REST
Before using any of the request data, make the following replacements:
- PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of your Google Cloud project
- LOCATION: The region where your dataset is located, such as
us-central1. - DATASET_ID: The unique identifier of your dataset that contains files to list.
- FILE_ID: The unique identifier of the file to delete, which is given when you list dataset files.
HTTP method and URL:
DELETE https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID/adaptiveMtFiles/FILE_ID
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER_OR_ID" \
"https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID/adaptiveMtFiles/FILE_ID"
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID/adaptiveMtFiles/FILE_ID" | Select-Object -Expand Content
You should receive a successful status code (2xx) and an empty response.
Before trying this sample, follow the Java setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Java API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Java
/** Deletes an AdaptiveMtFile. */
privatestaticvoiddeleteAdaptiveMtFile(
TranslationServiceClienttranslationServiceClient,StringfileId){
System.out.println("Deleting AdaptiveMtFile");
translationServiceClient.deleteAdaptiveMtFile(fileId);
}
Before trying this sample, follow the Node.js setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Node.js API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Node.js
asyncfunctiondeleteAdaptiveMtFile(){
constrequest={
name:`projects/${projectId}/locations/${location}/adaptiveMtDatasets/${
adaptiveMtDatasetName}/adaptiveMtFiles/${adaptive_mt_file_id}`,
}const[response]=awaittranslationClient.deleteAdaptiveMtFile(request)
console.log('Deleting file')
console.log(response)
}
Before trying this sample, follow the Python setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Python API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Python
defdelete_adaptive_mt_file():
# Create a client
client = translate.TranslationServiceClient()
# Initialize the request
request = translate.DeleteAdaptiveMtFileRequest(
name="projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID/adaptiveMtFiles/FILE_ID"
)
# Make the request
response = client.delete_adaptive_mt_file(request)
# Handle the response
print(response)
Delete datasets
Delete a dataset to remove all its data.
REST
Before using any of the request data, make the following replacements:
- PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of your Google Cloud project
- LOCATION: The region where your source dataset is located, such
as
us-central1. - DATASET_ID: The unique identifier of the dataset to delete.
HTTP method and URL:
DELETE https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER_OR_ID" \
"https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID"
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://translation.googleapis.com/v3/projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID" | Select-Object -Expand Content
You should receive a successful status code (2xx) and an empty response.
Before trying this sample, follow the Java setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Java API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Java
/** Deletes an AdaptiveMtDataset. */
privatestaticvoiddeleteAdaptiveMtDataset(
TranslationServiceClienttranslationServiceClient,StringprojectId,StringdatasetId){
System.out.println("Deleting AdaptiveMtDataset");
StringadaptiveMtDatasetName=
String.format(
"projects/%s/locations/LOCATION/adaptiveMtDatasets/%s",projectId,datasetId);
translationServiceClient.deleteAdaptiveMtDataset(adaptiveMtDatasetName);
}
publicstaticvoidmain(String[]args){
StringprojectName="PROJECT_NAME";
StringdatasetId="java-dataset-test";
StringgcsUri="gs://SOURCE_LOCATION/FILE.tsv";
try(TranslationServiceClienttranslationServiceClient=TranslationServiceClient.create()){
createAdaptiveMtDataset(translationServiceClient,projectName,datasetId);
listAdaptiveMtDatasets(translationServiceClient,projectName);
getAdaptiveMtDataset(translationServiceClient,projectName,datasetId);
StringfileId=
importAdaptiveMtFile(translationServiceClient,projectName,datasetId,gcsUri);
listAdaptiveMtFiles(translationServiceClient,projectName,datasetId);
getAdaptiveMtFile(translationServiceClient,fileId);
adaptiveMtTranslate(translationServiceClient,projectName,datasetId);
deleteAdaptiveMtFile(translationServiceClient,fileId);
deleteAdaptiveMtDataset(translationServiceClient,projectName,datasetId);
}catch(java.io.IOExceptione){
System.out.println(e.toString());
}
}
Before trying this sample, follow the Node.js setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Node.js API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Node.js
asyncfunctiondeleteAdaptiveMtDataset(){
constrequest={
name:`projects/${projectId}/locations/${location}/adaptiveMtDatasets/${
adaptiveMtDatasetName}`
}awaittranslationClient.deleteAdaptiveMtDataset(request)
console.log('Deleted dataset')
}
Before trying this sample, follow the Python setup instructions in the
Cloud Translation quickstart using
client libraries.
For more information, see the
Cloud Translation Python API
reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Python
defdelete_adaptive_mt_dataset():
# Create a client
client = translate.TranslationServiceClient()
# Initialize the request
request = translate.DeleteAdaptiveMtDatasetRequest(
name="projects/PROJECT_ID/locations/LOCATION/adaptiveMtDatasets/DATASET_ID"
)
# Make the request
response = client.delete_adaptive_mt_dataset(request)
# Handle the response
print(response)