Exploring the benefits of Amazon Translate – AWS Application Services for AI/ML – MLS-C01 Study Guide
Exploring the benefits of Amazon Translate
Some of the benefits of using Amazon Translate include the following:
It uses neural machine translation, which mimics the way the human brain works.
You do not need to maintain resources or infrastructures for the Translation action.
Produces high-quality results and maintains their consistency.
You can customize brand names and model names. Other unique terms too can get translated using the custom terminology feature.
Can be easily integrated with applications through APIs.
Amazon Translate scales itself when you need it to do more.
Next, you will get hands-on with Amazon Translate.
Getting hands-on with Amazon Translate
In this section, you will build a product by integrating AWS Lambda with Amazon Rekognition, Amazon Comprehend, and Amazon Translate to read an image file stored in an S3 bucket. Then, you will detect the language of the text that has been extracted from the image so that you can translate it into English. You will also use CloudWatch to print the translated output. The following is a diagram of our use case:
Figure 8.17 – Architecture diagram of the required use case
Let’s start by creating an IAM role:
Navigate to the IAM console page.
Select Roles from the left-hand menu.
Select Create role.
Select Lambda as the trusted entity.
Add the following managed policies:
AmazonS3ReadOnlyAccess
AmazonRekognitionFullAccess
ComprehendFullAccess
CloudWatchFullAccess
TranslateFullAccess
Save the role as language-translation-from-image.
The next immediate step is to create a Lambda function. Navigate to Lambda > Functions > Create Function.
Name the function language-detection-from-image.
Set the runtime to Python 3.6.
Use an existing role; that is, language-detection-from-image-role.
Paste the code available at https://github.com/PacktPublishing/AWS-Certified-Machine-Learning-Specialty-MLS-C01-Certification-Guide-Second-Edition/blob/main/Chapter08/Amazon%20Translate%20Demo/lambda_function/lambda_function.py and click Deploy. You will use the translate_text API to translate the input text.
The next step is to create a bucket called language-translation-from-image.
Create a folder named image. Then, navigate to Properties > Events> Add notification.
Fill in the required fields, as shown here, and click on Save (please make sure you select .jpg as the suffix; otherwise, it will trigger the Lambda function for any object creation process):
Name: translate-language-image
Events: All object create events
Prefix: image/
Suffix: .jpg
Send to: Lambda Function
Lambda: language-translation-from-image
Navigate to Amazon S3 > language-detection-image > input-image. Upload the sign-image.jpg image into the folder. This file is available in this book’s GitHub repository: https://github.com/PacktPublishing/AWS-Certified-Machine-Learning-Specialty-MLS-C01-Certification-Guide-Second-Edition/tree/main/Chapter08/Amazon%20Translate%20Demo/input_image.
Uploading this image will trigger the Lambda function. You can monitor the logs by going to CloudWatch > CloudWatch Logs > Log groups > /aws/lambda/language-translation-from-image.
Click on the streams and select the latest one. It will look as follows:
Figure 8.18 – The logs in CloudWatch for verifying the output
The translation is as follows:
Translation of the text from the Image :
{‘PREVENCION DEL COVID-19’: ‘PREVENTION OF COVID-19’,
‘LAVATE LAS MANOS EVITA EL CONTACTO NO TE TOQUES oJOs,
EVITA’: ‘WASHE HANDS AVOID CONTACT DO NOT TOUCH EYES’,
’60 SEGUNDOS CON CONTAGIADOS NARIZ O BOCA
AGLOMERACIONES’: ’60 SECONDS WITH CONTAGIOUS NOSE OR
MOUTH AGGLOMERATIONS’, ‘NO COMPARTAS NO VIAJES A MENOS
SI TE PONES ENFERMO’: “DON’T SHARE NOT TRAVEL UNLESS
YOU GET SICK”, ‘CUBIERTOS NI COMIDA QUE SEA NECESARIO