AWS AI Services
Explore AWS AI services that enable integration of pre-trained machine learning tools including text, speech, vision, and generative AI. Understand how to use these services through Python code and AWS Console, and get familiar with tools like Amazon Rekognition, Comprehend, Lex, and CodeWhisperer to enhance data analytics and application development.
Amazon AI services include a wide variety of pre-trained tools for developers to integrate AI functionality without having to understand the details of ML algorithms.
Many of the available AWS AI services are used by Amazon’s e-commerce site, so the deep-learning algorithms can be continuously updated based on new training data managed by AWS.
There are services to convert text to speech and vice versa (Amazon Polly, Amazon Transcribe), use AI in chatbots (Amazon Lex), analyze visual data (Amazon Rekognition), process text (Amazon Comprehend), and translate text (Amazon Translate).
Note: Other cloud-computing platforms, including Google Cloud and Microsoft Azure, also have pre-trained AI and ML models that can be used to benchmark the quality of the available AWS AI services.
Some available AWS AI services
The below table lists some available AWS AI services according to how they can be used:
Category | Use Case | Service |
Computer vision | Analyze images and videos | Amazon Rekognition |
Detect defects and automate inspection | Amazon Lookout for Vision | |
Utilize computer vision at the edge | AWS Panorama | |
Automated data extraction and analysis | Extract text and data | Amazon Textract |
Acquire insights from text | Amazon Comprehend | |
Control quality of automation | Amazon Augmented AI | |
Language AI | Build chatbots and virtual agents | Amazon Lex |
Automate speech recognition (speech-to-text) | Amazon Transcribe | |
Give apps a voice (text-to-speech) | Amazon Polly | |
Improve customer experience | Find accurate information faster (using natural-language search) | Amazon Kendra |
Personalize online experiences | Amazon Personalize | |
Engage audiences in every language | Amazon Translate | |
Business metrics | Forecast business metrics | Amazon Forecast |
Detect online fraud | Amazon Fraud Detector | |
Identify data anomalies | Amazon Lookout for Metrics | |
Code and DevOps | Improve application availability | Amazon DevOps Guru |
Automated code reviews | Amazon CodeGuru Reviewer | |
Eliminate costly, inefficient code | Amazon CodeGuru Profiler | |
Industrial AI | Detect abnormal machine conditions | Amazon Lookout for Equipment |
Predictive maintenance | Amazon Monitron | |
Healthcare | Store and analyze health data | Amazon Healthlake |
Extract health data | Amazon Comprehend Medical |
Using an AWS AI service from code
Let’s pick an AWS AI service and consider how we can use it from Python code. In the code example below, we use Amazon Comprehend through the boto3 Python library from AWS. The code is designed to detect the language of the text contained in sample.txt. We then use the pycountry library to display the detected language(s), along with an accuracy score from Amazon Comprehend’s ML model.
To run the Python code below successfully, change the values in config.env to correspond to an accessible AWS account.
Using an AWS AI service from the Console
Many of the AWS AI services can be used from the AWS Console. For example, Amazon Rekognition is designed to analyze images and videos. Let’s try it on the AWS Console.
From the AWS Console’s search bar, we navigate to the “Amazon Rekognition” section and click the “Try Demo” button.
The default demo is for “Label detection.” When provided with an image, Amazon Rekognition attempts to automatically label items within the image—for example, a person and a skateboard. Use the “Upload” button to label an image from your local computer. Alternatively, enter a URL for an image to label.
Such demos provide a quick way to test Amazon Rekognition capabilities without running code.
As another example, we can use the “Celebrity recognition” demo in Amazon Rekognition to test the mode’s accuracy for detecting celebrities in photos. On the “Celebrity recognition” page, supply the URL of an image from Wikipedia and click the “Go” button.
According to the “Results” section in the above screenshot, the algorithm recognizes Pitbull with 91% accuracy, Jennifer Lopez with 75.8% accuracy, and Jordan Carver with 75.3% accuracy. This photo does indeed include Pitbull and Jennifer Lopez. However, the first person from the left is actually the Brazilian singer Claudia Leitte, not the German model Jordan Carver.
Note: AI services aren’t perfect, and it’s worth considering how beneficial it is to use them in various scenarios (and to integrate them into various products) even when the algorithms make mistakes.
Generative AI services
The subfield of generative AI garnered more attention after the launch of ChatGPT by the startup OpenAI in late 2022. Generative AI models are designed to generate text and other content based on user prompts. For example, an image-based ML model called Stable Diffusion is able to create new images based on a text prompt.
As with other AI services, generative AI can sometimes make mistakes. In the above image of an astronaut riding a horse, we might notice that the astronaut’s arms are unrealistic. With text generation models, some responses can include creative “hallucinations” that contain errors in logic and facts.
The same generative AI model can also generate multiple content versions based on the same text prompt. For example, asking the same question to ChatGPT might not get the same answers. With image generation, often many prompts and iterations are required to produce a usable image.
Amazon Bedrock
In 2023, AWS announced several efforts within generative AI, including Amazon Bedrock. One goal of Amazon Bedrock is to make the ML models behind some generative AI tools (called foundation models (FMs)) more accessible to developers.
Related use cases include:
Text generation
Text summarization
Search
Chatbots
Image generation
Personalization
Related ML models include:
Stable Diffusion (from Stability AI)
Claude (from Anthropic)
Jurassic-2 (from AI21 Labs)
Amazon Titan
Note: Generative AI and ML are quickly evolving areas. There are often many ML models available for the same use case (for example, machine translation), including open-source ML models. Make sure to test the quality of various solutions to understand which might best fit your scenarios.
Amazon CodeWhisperer
Generative AI models have also been trained on computer code. GitHub Copilot was initially launched in 2021 and is one of the first commercially available tools for code generation. It’s based on the OpenAI Codex ML model, which was trained on public source code (and may have coding errors).
Amazon CodeWhisperer was launched in 2023 and is conceptually similar to GitHub Copilot. In addition to training on public source code, Amazon has trained CodeWhisperer on AWS-specific code so that it can be more helpful for working with AWS services. The CodeWhisperer Individual Tier is free to use. The CodeWhisperer Professional Tier has more administrative features and a monthly fee.
Amazon CodeWhisperer is integrated with development environments such as Visual Studio Code (VSCode). Let’s proceed with setting up CodeWhisperer on VSCode.
First, we need to install the AWS Toolkit extension for VSCode. Find this extension, and click the “Install” button.
After installing the extension, click the “AWS” logo on the left navigation bar. Then, find the “Developer Tools” panel, and expand the “CodeWhisperer” category in this panel. Click “Start” under the CodeWhisperer category.
Clicking the button “Sign up or Sign in” allows us to set up a free AWS Builder ID for a CodeWhisperer individual account.
Several prompts then appear. Choose “Copy Code and Proceed” in the prompt “Copy Code for AWS Builder ID.” Choose “Open” in the prompt “Do you want Code to open the external website?”
In the browser, paste the code into the “Authorize request” window, and then proceed to create a new AWS Builder ID using your email address.
Next, verify your email address and choose your password. Click “Allow” in the prompt “Allow AWS Toolkit for VSCode to access your data?”
Switching back to Visual Studio Code, we click “Yes, keep using AWS Builder ID with CodeWhisperer...” (if this pop-up appears). The screenshot below shows Amazon’s welcome guide to CodeWhisperer, including information on keyboard shortcuts.
As an example, we can type a comment, “write Python code to upload a file to Amazon S3,” and then use CodeWhisperer keyboard shortcuts (“Option+C” on Mac or “Alt+C” on Windows) to manually request code suggestions. CodeWhisperer provides code suggestions in italics, and we can press "Tab" to accept a suggestion.
The code suggested by Amazon CodeWhisperer might not always fit our needs. For example, the above code has no methods for authentication nor does it include error handling. Verifying any suggested code with AWS API documentation might be a good idea to avoid errors introduced by the underlying ML models.