diff --git a/translate/automl/automlTranslationDataset.js b/translate/automl/automlTranslationDataset.js deleted file mode 100644 index 851ad9f6ab..0000000000 --- a/translate/automl/automlTranslationDataset.js +++ /dev/null @@ -1,325 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * This application demonstrates how to perform basic operations on dataset - * with the Google AutoML Translation API. - * - * For more information, see the documentation at - * https://cloud.google.com/translate/automl/docs - */ - -'use strict'; - -async function createDataset(projectId) { - // [START automl_translation_create_dataset] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - const computeRegion = 'us-central1'; - const datasetName = 'myDataset'; - const source = 'en'; - const target = 'ja'; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // Specify the source and target language. - const datasetSpec = { - sourceLanguageCode: source, - targetLanguageCode: target, - }; - - // Set dataset name and dataset specification. - const datasetInfo = { - displayName: datasetName, - translationDatasetMetadata: datasetSpec, - }; - - // Create a dataset with the dataset specification in the region. - const [dataset] = await client.createDataset({ - parent: projectLocation, - dataset: datasetInfo, - }); - - // Display the dataset information - console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset id: ${dataset.name.split('/').pop(-1)}`); - console.log(`Dataset display name: ${dataset.displayName}`); - console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log('Translation dataset specification:'); - console.log( - `\tSource language code: ${dataset.translationDatasetMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${dataset.translationDatasetMetadata.targetLanguageCode}` - ); - console.log('Dataset create time:'); - console.log(`\tseconds: ${dataset.createTime.seconds}`); - console.log(`\tnanos: ${dataset.createTime.nanos}`); - // [END automl_translation_create_dataset] -} - -async function listDatasets(projectId, computeRegion, filter) { - // [START automl_translation_list_datasets] - const automl = require('@google-cloud/automl'); - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const filter = `filter expressions, must specify field e.g. “imageClassificationModelMetadata:*”`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the datasets available in the region by applying filter. - const [datasets] = await client.listDatasets({ - parent: projectLocation, - filter: filter, - }); - - // Display the dataset information. - if (datasets.length === 0) { - console.log('No datasets found!'); - return; - } - console.log('List of datasets:'); - datasets.forEach(dataset => { - console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset id: ${dataset.name.split('/').pop(-1)}`); - console.log(`Dataset display name: ${dataset.displayName}`); - console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log('Translation dataset specification:'); - console.log( - `\tSource language code: ${dataset.translationDatasetMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${dataset.translationDatasetMetadata.targetLanguageCode}` - ); - console.log('Dataset create time:'); - console.log(`\tseconds: ${dataset.createTime.seconds}`); - console.log(`\tnanos: ${dataset.createTime.nanos}`); - }); - // [END automl_translation_list_datasets] -} - -async function getDataset(projectId, computeRegion, datasetId) { - // [START automl_translation_get_dataset] - const automl = require('@google-cloud/automl'); - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Get complete detail of the dataset. - const [dataset] = await client.getDataset({name: datasetFullId}); - - // Display the dataset information. - console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset id: ${dataset.name.split('/').pop(-1)}`); - console.log(`Dataset display name: ${dataset.displayName}`); - console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log('Translation dataset specification:'); - console.log( - `\tSource language code: ${dataset.translationDatasetMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${dataset.translationDatasetMetadata.targetLanguageCode}` - ); - console.log('Dataset create time:'); - console.log(`\tseconds: ${dataset.createTime.seconds}`); - console.log(`\tnanos: ${dataset.createTime.nanos}`); - - // [END automl_translation_get_dataset] -} - -async function importData(projectId, computeRegion, datasetId, path) { - // [START automl_translation_import_data] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - // const path = `string or array of .csv paths in AutoML Vision CSV format, e.g. “gs://myproject/mytraindata.csv”;` - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Get the multiple Google Cloud Storage URIs. - const inputUris = path.split(','); - const inputConfig = { - gcsSource: { - inputUris: inputUris, - }, - }; - - // Import data from the input URI. - const [operation] = await client.importData({ - name: datasetFullId, - inputConfig: inputConfig, - }); - console.log('Processing import...'); - const operationResponses = await operation.promise(); - // The final result of the operation. - if (operationResponses[2].done === true) { - console.log('Data imported.'); - } - - // [END automl_translation_import_data] -} - -async function deleteDataset(projectId, computeRegion, datasetId) { - // [START automl_translation_delete_dataset] - const automl = require('@google-cloud/automl'); - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Delete a dataset. - const [operations] = await client.deleteDataset({name: datasetFullId}); - const operationResponses = await operations.promise(); - // The final result of the operation. - if (operationResponses[2].done === true) console.log('Dataset deleted.'); - - // [END automl_translation_delete_dataset] -} - -require('yargs') - .demand(1) - .options({ - computeRegion: { - alias: 'c', - type: 'string', - default: 'us-central1', - requiresArg: true, - description: 'region name e.g. "us-central1"', - }, - datasetName: { - alias: 'n', - type: 'string', - default: 'testDataSet', - requiresArg: true, - description: 'Name of the Dataset', - }, - datasetId: { - alias: 'i', - type: 'string', - requiresArg: true, - description: 'Id of the dataset', - }, - filter: { - alias: 'f', - default: 'translationDatasetMetadata:*', - type: 'string', - requiresArg: true, - description: 'Name of the Dataset to search for', - }, - multilabel: { - alias: 'm', - type: 'string', - default: false, - requiresArg: true, - description: - 'Type of the classification problem, ' + - 'False - MULTICLASS, True - MULTILABEL.', - }, - outputUri: { - alias: 'o', - type: 'string', - requiresArg: true, - description: 'URI (or local path) to export dataset', - }, - path: { - alias: 'p', - type: 'string', - global: true, - default: 'gs://nodejs-docs-samples-vcm/en-ja.csv', - requiresArg: true, - description: 'URI or local path to input .csv, or array of .csv paths', - }, - projectId: { - alias: 'z', - type: 'number', - default: process.env.GCLOUD_PROJECT, - requiresArg: true, - description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"', - }, - source: { - alias: 's', - type: 'string', - requiresArg: true, - description: 'The source language to be translated from', - }, - target: { - alias: 't', - type: 'string', - requiresArg: true, - description: 'The target language to be translated to', - }, - }) - .command('create-dataset', 'creates a new Dataset', {}, opts => - createDataset( - opts.projectId, - opts.computeRegion, - opts.datasetName, - opts.source, - opts.target - ) - ) - .command('list-datasets', 'list all Datasets', {}, opts => - listDatasets(opts.projectId, opts.computeRegion, opts.filter) - ) - .command('get-dataset', 'Get a Dataset', {}, opts => - getDataset(opts.projectId, opts.computeRegion, opts.datasetId) - ) - .command('delete-dataset', 'Delete a dataset', {}, opts => - deleteDataset(opts.projectId, opts.computeRegion, opts.datasetId) - ) - .command('import-data', 'Import labeled items into dataset', {}, opts => - importData(opts.projectId, opts.computeRegion, opts.datasetId, opts.path) - ) - .example('node $0 create-dataset -n "newDataSet" -s "en" -t "ja"') - .example('node $0 list-datasets -f "translationDatasetMetadata:*"') - .example('node $0 get-dataset -i "DATASETID"') - .example('node $0 delete-dataset -i "DATASETID"') - .example( - 'node $0 import-data -i "dataSetId" -p "gs://myproject/mytraindata.csv"' - ) - .wrap(120) - .recommendCommands() - .help() - .strict().argv; diff --git a/translate/automl/automlTranslationModel.js b/translate/automl/automlTranslationModel.js deleted file mode 100644 index 602a468954..0000000000 --- a/translate/automl/automlTranslationModel.js +++ /dev/null @@ -1,402 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * This application demonstrates how to perform basic operations on model - * with the Google AutoML Translation API. - * - * For more information, see the documentation at - * https://cloud.google.com/translate/automl/docs - */ - -'use strict'; - -async function createModel(projectId, computeRegion, datasetId, modelName) { - // [START automl_translation_create_model] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - // const modelName = `Name of the model, e.g. "myModel"`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // Set model name and dataset. - const myModel = { - displayName: modelName, - datasetId: datasetId, - translationModelMetadata: {}, - }; - - // Create a model with the model metadata in the region. - const [operation, response] = await client.createModel({ - parent: projectLocation, - model: myModel, - }); - const initialApiResponse = response; - console.log('Training operation name: ', initialApiResponse.name); - console.log('Training started...'); - const [model] = await operation.promise(); - // The final result of the operation. - console.log(model); - // Retrieve deployment state. - let deploymentState = ''; - if (model.deploymentState === 1) { - deploymentState = 'deployed'; - } else if (model.deploymentState === 2) { - deploymentState = 'undeployed'; - } - - // Display the model information. - console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split('/').pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log('Model create time:'); - console.log(`\tseconds: ${model.createTime.seconds}`); - console.log(`\tnanos: ${model.createTime.nanos}`); - console.log(`Model deployment state: ${deploymentState}`); - - // [END automl_translation_create_model] -} - -async function listModels(projectId, computeRegion, filter) { - // [START automl_translation_list_models] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const filter = `filter expressions, must specify field, e.g. "translationDatasetMetadata:*”`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the models available in the region by applying filter. - const [models] = await client.listModels({ - parent: projectLocation, - filter: filter, - }); - - // Display the model information. - console.log('List of models:'); - models.forEach(model => { - console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split('/').pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log(`Model dataset id: ${model.datasetId}`); - console.log('Model create time:'); - console.log(`\tseconds: ${model.createTime.seconds}`); - console.log(`\tnanos: ${model.createTime.nanos}`); - console.log('Model update time:'); - console.log(`\tseconds: ${model.updateTime.seconds}`); - console.log(`\tnanos: ${model.updateTime.nanos}`); - console.log(`Model deployment state: ${model.deploymentState}`); - console.log('\n'); - }); - - // [END automl_translation_list_models] -} - -async function getModel(projectId, computeRegion, modelId) { - // [START automl_translation_get_model] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Get complete detail of the model. - const [model] = await client.getModel({name: modelFullId}); - - // Display the model information. - console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split('/').pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log(`Model dataset id: ${model.datasetId}`); - if (model.modelMetadata === 'translationModelMetadata') { - console.log('Translation model metadata:'); - console.log(`\tBase model: ${model.translationModelMetadata.baseModel}`); - console.log( - `\tSource language code: ${model.translationModelMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${model.translationModelMetadata.targetLanguageCode}` - ); - } else if (model.modelMetadata === 'textClassificationModelMetadata') { - console.log( - `Text classification model metadata: ${model.textClassificationModelMetadata}` - ); - } else if (model.modelMetadata === 'imageClassificationModelMetadata') { - console.log('Image classification model metadata:'); - console.log( - `\tBase model id: ${model.imageClassificationModelMetadata.baseModelId}` - ); - console.log( - `\tTrain budget: ${model.imageClassificationModelMetadata.trainBudget}` - ); - console.log( - `\tTrain cost: ${model.imageClassificationModelMetadata.trainCost}` - ); - console.log( - `\tStop reason: ${model.imageClassificationModelMetadata.stopReason}` - ); - } - console.log('Model create time:'); - console.log(`\tseconds: ${model.createTime.seconds}`); - console.log(`\tnanos: ${model.createTime.nanos}`); - console.log('Model update time:'); - console.log(`\tseconds: ${model.updateTime.seconds}`); - console.log(`\tnanos: ${model.updateTime.nanos}`); - console.log(`Model deployment state: ${model.deploymentState}`); - - // [END automl_translation_get_model] -} - -async function listModelEvaluations(projectId, computeRegion, modelId, filter) { - // [START automl_translation_list_model_evaluations] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const filter = `filter expressions, must specify field, e.g. “imageClassificationModelMetadata:*”`; - - // Get the full path of the model. - const modelFullId = await client.modelPath(projectId, computeRegion, modelId); - - // List all the model evaluations in the model by applying filter. - const [elements] = client.listModelEvaluations({ - parent: modelFullId, - filter: filter, - }); - console.log('List of model evaluations:'); - elements.forEach(element => { - console.log(element); - }); - - // [END automl_translation_list_model_evaluations] -} - -async function getModelEvaluation( - projectId, - computeRegion, - modelId, - modelEvaluationId -) { - // [START automl_translation_get_model_evaluation] - const automl = require('@google-cloud/automl'); - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const modelEvaluationId = `Id of your model evaluation, e.g “ICN12345” - - // Get the full path of the model evaluation. - const modelEvaluationFullId = client.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - // Get complete detail of the model evaluation. - const [response] = await client.getModelEvaluation({ - name: modelEvaluationFullId, - }); - console.log(response); - - // [END automl_translation_get_model_evaluation] -} - -async function deleteModel(projectId, computeRegion, modelId) { - // [START automl_translation_delete_model] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Delete a model. - const [operation] = await client.deleteModel({name: modelFullId}); - const operationResponse = await operation.promise(); - // The final result of the operation. - if (operationResponse[2].done === true) console.log('Model deleted.'); - - // [END automl_translation_delete_model] -} - -async function getOperationStatus(operationFullId) { - // [START automl_translation_get_operation_status] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const operationFullId = `Full name of an operation, eg. “Projects//locations/us-central1/operations/ - - // Get the latest state of a long-running operation. - const [responses] = await client.operationsClient.getOperation( - operationFullId - ); - console.log(`Operation status: ${responses}`); - // [END automl_translation_get_operation_status] -} - -require('yargs') - .demand(1) - .options({ - computeRegion: { - alias: 'c', - type: 'string', - default: 'us-central1', - requiresArg: true, - description: 'region name e.g. "us-central1"', - }, - datasetId: { - alias: 'i', - type: 'string', - requiresArg: true, - description: 'Id of the dataset', - }, - filter: { - alias: 'f', - default: '', - type: 'string', - requiresArg: true, - description: 'Name of the Dataset to search for', - }, - modelName: { - alias: 'm', - type: 'string', - default: false, - requiresArg: true, - description: 'Name of the model', - }, - modelId: { - alias: 'a', - type: 'string', - default: '', - requiresArg: true, - description: 'Id of the model', - }, - modelEvaluationId: { - alias: 'e', - type: 'string', - default: '', - requiresArg: true, - description: 'Id of the model evaluation', - }, - operationFullId: { - alias: 'o', - type: 'string', - default: '', - requiresArg: true, - description: 'Full name of an operation', - }, - projectId: { - alias: 'z', - type: 'number', - default: process.env.GCLOUD_PROJECT, - requiresArg: true, - description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"', - }, - }) - .command('create-model', 'creates a new Model', {}, opts => - createModel( - opts.projectId, - opts.computeRegion, - opts.datasetId, - opts.modelName - ) - ) - .command( - 'get-operation-status', - 'Gets status of current operation', - {}, - opts => getOperationStatus(opts.operationFullId) - ) - .command('list-models', 'list all Models', {}, opts => - listModels(opts.projectId, opts.computeRegion, opts.filter) - ) - .command('get-model', 'Get a Model', {}, opts => - getModel(opts.projectId, opts.computeRegion, opts.modelId) - ) - .command('list-model-evaluations', 'List model evaluations', {}, opts => - listModelEvaluations( - opts.projectId, - opts.computeRegion, - opts.modelId, - opts.filter - ) - ) - .command('get-model-evaluation', 'Get model evaluation', {}, opts => - getModelEvaluation( - opts.projectId, - opts.computeRegion, - opts.modelId, - opts.modelEvaluationId - ) - ) - .command('delete-model', 'Delete a Model', {}, opts => - deleteModel(opts.projectId, opts.computeRegion, opts.modelId) - ) - .example('node $0 create-model -i "DatasetID" -m "myModelName"') - .example('node $0 get-operation-status -i "datasetId" -o "OperationFullID"') - .example('node $0 list-models -f "translationModelMetadata:*"') - .example('node $0 get-model -a "ModelID"') - .example('node $0 list-model-evaluations -a "ModelID"') - .example('node $0 get-model-evaluation -a "ModelId" -e "ModelEvaluationID"') - .example('node $0 delete-model -a "ModelID"') - .wrap(120) - .recommendCommands() - .help() - .strict().argv; diff --git a/translate/automl/automlTranslationPredict.js b/translate/automl/automlTranslationPredict.js deleted file mode 100644 index 54516237e0..0000000000 --- a/translate/automl/automlTranslationPredict.js +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * This application demonstrates how to perform basic operations on prediction - * with the Google AutoML Translation API. - * - * For more information, see the documentation at - * https://cloud.google.com/translate/automl/docs - */ - -'use strict'; - -async function predict( - projectId, - computeRegion, - modelId, - filePath, - translationAllowFallback -) { - // [START automl_translation_predict] - const automl = require('@google-cloud/automl'); - const fs = require('fs'); - - // Create client for prediction service. - const client = new automl.PredictionServiceClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const filePath = `local text file path of content to be classified, e.g. "./resources/test.txt"`; - // const translationAllowFallback = `use Google translation model as fallback, e.g. "False" or "True"`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Read the file content for translation. - const content = fs.readFileSync(filePath, 'utf8'); - - // Set the payload by giving the content of the file. - const payload = { - textSnippet: { - content: content, - }, - }; - - // Params is additional domain-specific parameters. - // TranslationAllowFallback allows to use Google translation model. - let params = {}; - if (translationAllowFallback) { - params = { - translationAllowFallback: true, - }; - } - - const responses = await client.predict({ - name: modelFullId, - payload: payload, - params: params, - }); - - const response = responses[0]; - console.log( - 'Translated Content: ', - response.payload[0].translation.translatedContent.content - ); - - // [END automl_translation_predict] -} - -require('yargs') - .demand(1) - .options({ - computeRegion: { - alias: 'c', - type: 'string', - default: 'us-central1', - requiresArg: true, - description: 'region name e.g. "us-central1"', - }, - filePath: { - alias: 'f', - default: './resources/testInput.txt', - type: 'string', - requiresArg: true, - description: 'local text file path of the content to be classified', - }, - modelId: { - alias: 'i', - type: 'string', - requiresArg: true, - description: 'Id of the model which will be used for text classification', - }, - projectId: { - alias: 'z', - type: 'number', - default: process.env.GCLOUD_PROJECT, - requiresArg: true, - description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"', - }, - translationAllowFallback: { - alias: 't', - type: 'string', - default: 'False', - requiresArg: true, - description: - 'Use true if AutoML will fallback to use a Google translation model for' + - 'translation requests if the specified AutoML translation model cannot' + - 'serve the request. Use false to not use Google translation model.', - }, - }) - .command('predict', 'classify the content', {}, opts => - predict( - opts.projectId, - opts.computeRegion, - opts.modelId, - opts.filePath, - opts.translationAllowFallback - ) - ) - .example( - 'node $0 predict -i "modelId" -f "./resources/testInput.txt" -t "False"' - ) - .wrap(120) - .recommendCommands() - .help() - .strict().argv; diff --git a/translate/automl/resources/testInput.txt b/translate/automl/resources/testInput.txt deleted file mode 100644 index acea938083..0000000000 --- a/translate/automl/resources/testInput.txt +++ /dev/null @@ -1 +0,0 @@ -Tell me how this ends diff --git a/translate/test/automlTranslation.test.js b/translate/test/automlTranslation.test.js deleted file mode 100644 index 89387549c5..0000000000 --- a/translate/test/automlTranslation.test.js +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const cmdDataset = 'node automlTranslationDataset.js'; -const cmdModel = 'node automlTranslationModel.js'; -const cmdPredict = 'node automlTranslationPredict.js'; - -const testDataSetName = 'testDataSet'; -const dummyDataSet = 'dummyDataSet'; -const testModelName = 'dummyModel'; -const sampleText = './resources/testInput.txt'; -const donotdeleteModelId = 'TRL188026453969732486'; - -describe.skip('automl sample tests', () => { - it('should create a create, list, and delete a dataset', async () => { - // Check to see that this dataset does not yet exist - let output = execSync(`${cmdDataset} list-datasets`); - assert.match(output, new RegExp(testDataSetName)); - - // Create dataset - output = execSync(`${cmdDataset} create-dataset -n "${testDataSetName}"`); - const dataSetId = output.split('\n')[1].split(':')[1].trim(); - assert.match( - output, - new RegExp(`Dataset display name: ${testDataSetName}`) - ); - - // Delete dataset - output = execSync(`${cmdDataset} delete-dataset -i "${dataSetId}"`); - assert.match(output, /Dataset deleted./); - }); - - // We make two models running this test, see hard-coded workaround below - it('should create a dataset, import data, and start making a model', async () => { - // Check to see that this dataset does not yet exist - let output = execSync(`${cmdDataset} list-datasets`); - assert.notMatch(output, new RegExp(dummyDataSet)); - - // Create dataset - output = execSync(`${cmdDataset} create-dataset -n "${dummyDataSet}"`); - const dataSetId = output.split('\n')[1].split(':')[1].trim(); - assert.match(output, new RegExp(`Dataset display name: ${dummyDataSet}`)); - - // Import Data - output = execSync( - `${cmdDataset} import-data -i "${dataSetId}" -p "gs://nodejs-docs-samples-vcm/flowerTraindata20lines.csv"` - ); - assert.match(output, /Data imported./); - - // Check to make sure model doesn't already exist - output = execSync(`${cmdModel} list-models`); - assert.notMatch(output, testModelName); - - // Begin training dataset, getting operation ID for next operation - output = execSync( - `${cmdModel} create-model -i "${dataSetId}" -m "${testModelName}" -t "2"` - ); - const operationName = output.split('\n')[0].split(':')[1].trim(); - assert.match(output, 'Training started...'); - - // Poll operation status, here confirming that operation is not complete yet - output = execSync( - `${cmdModel} get-operation-status -i "${dataSetId}" -o "${operationName}"` - ); - assert.match(output, /done: false/); - }); - - it('should run get model (from a prexisting model)', async () => { - // Confirm dataset exists - let output = execSync(`${cmdDataset} list-datasets`); - assert.match(output, /me_do_not_delete/); - - // List model evaluations, confirm model exists - output = execSync( - `${cmdModel} list-model-evaluations -a "${donotdeleteModelId}"` - ); - assert.match(output, /translationEvaluationMetrics:/); - - // Get model evaluation - output = execSync(`${cmdModel} get-model -a "${donotdeleteModelId}"`); - assert.match(output, /Model deployment state: DEPLOYED/); - }); - - it('should run Prediction from prexisting model', async () => { - // Confirm dataset exists - let output = execSync(`${cmdDataset} list-datasets`); - assert.match(output, /me_do_not_delete/); - - // List model evaluations, confirm model exists - output = execSync( - `${cmdModel} list-model-evaluations -a "${donotdeleteModelId}"` - ); - assert.match(output, 'translationEvaluationMetrics:'); - - // Run prediction on 'testImage.jpg' in resources folder - output = execSync( - `${cmdPredict} predict -i "${donotdeleteModelId}" -f "${sampleText}" -t "False"` - ); - assert.match( - output, - /Translated Content: {2}これがどのように終わるか教えて/ - ); - }); - - // List datasets - it('should list datasets', async () => { - const output = execSync(`${cmdDataset} list-datasets`); - assert.match(output, /List of datasets:/); - }); -});