Hands-On Lab: Exploring Basic AI Concepts and Terminology
AI Concepts and Terminology
Hands-On Lab: Exploring Basic AI Concepts and Terminology
Welcome to this guided hands-on lab! This module bridges the theoretical concepts from Chapter 1 (Fundamentals of AI and ML) with practical reality. You will interact with pre-trained Artificial Intelligence (AI) models using AWS managed services to perform Computer Vision and Natural Language Processing (NLP) tasks.
By completing this lab, abstract terms like unstructured data, real-time inferencing, and confidence scores will become tangible.
Prerequisites
Before starting, ensure you have the following:
- AWS Account: An active AWS account with administrative or developer access.
- CLI Tools: AWS CLI installed and configured (
aws configure) on your local machine or AWS CloudShell. - Prior Knowledge: Familiarity with basic terminal commands and a conceptual understanding of AI vs. Machine Learning (ML).
Learning Objectives
- Differentiate AI fields in practice: Use distinct services for Computer Vision (Amazon Rekognition) and Natural Language Processing (Amazon Comprehend).
- Understand Data Types: Work with unstructured data formats (images and raw text) rather than tabular data.
- Perform Real-Time Inferencing: Send data to an ML model and receive immediate probabilistic predictions.
- Analyze Model Outputs: Interpret JSON responses containing confidence scores to understand the probabilistic nature of AI.
Architecture Overview
This lab uses a simple serverless architecture to demonstrate real-time inferencing on unstructured data.
Step-by-Step Instructions
Step 1: Prepare Unstructured Data (Amazon S3)
In Machine Learning, images and text are considered unstructured data. Deep learning models are particularly adept at processing this format. Let's create a storage bucket and upload a sample image.
# 1. Create a globally unique S3 bucket (replace <YOUR_ACCOUNT_ID>)
aws s3 mb s3://brainybee-lab-vision-<YOUR_ACCOUNT_ID>
# 2. Download a sample image of a city skyline (or use any local JPEG)
curl -o sample.jpg https://raw.githubusercontent.com/aws-samples/amazon-rekognition-developer-guide/master/images/city.jpg
# 3. Upload the unstructured data to S3
aws s3 cp sample.jpg s3://brainybee-lab-vision-<YOUR_ACCOUNT_ID>/📸 Screenshot: A terminal showing the successful
upload: sample.jpg to s3://...output.
▶Console alternative
- Navigate to Amazon S3 in the AWS Console.
- Click Create bucket, name it
brainybee-lab-vision-<YOUR_ACCOUNT_ID>, and click Create bucket. - Select your new bucket, click Upload, and upload a local image file named
sample.jpg.
Step 2: Real-Time Inferencing with Computer Vision
Computer Vision is an AI field enabling systems to derive information from images. We will use Amazon Rekognition to perform real-time inferencing (getting immediate predictions) on our unstructured image.
# Run real-time inferencing to detect labels (objects, scenes) in the image
aws rekognition detect-labels \
--image '{"S3Object":{"Bucket":"brainybee-lab-vision-<YOUR_ACCOUNT_ID>","Name":"sample.jpg"}}' \
--max-labels 5[!TIP] Look at the JSON response. Notice the
Confidenceattribute next to each label. AI models do not return absolute facts; they return probabilities based on their training data.
▶Console alternative
- Navigate to Amazon Rekognition in the AWS Console.
- In the left sidebar, click Label detection.
- Under the demo section, expand the Upload panel and upload your
sample.jpg. - Observe the detected labels and their percentage scores (confidence) in the Results pane.
Step 3: Natural Language Processing (NLP)
Natural Language Processing (NLP) allows computers to interpret human language. We will use Amazon Comprehend to analyze the sentiment of unstructured text.
# Perform NLP inferencing to determine text sentiment
aws comprehend detect-sentiment \
--text "Artificial intelligence is a fascinating and transformative technology, though data drift can occasionally cause headaches!" \
--language-code "en"📸 Screenshot: The JSON output from Comprehend showing a
Sentimentof MIXED or POSITIVE, along withSentimentScorebreakdowns.
▶Console alternative
- Navigate to Amazon Comprehend in the AWS Console.
- Scroll down to the Real-time analysis section.
- Paste the text:
"Artificial intelligence is a fascinating and transformative technology, though data drift can occasionally cause headaches!" - Click Analyze and view the Sentiment results in the Insights tab.
Checkpoints
Verify your progress after completing the steps above:
- Checkpoint 1: Run
aws s3 ls s3://brainybee-lab-vision-<YOUR_ACCOUNT_ID>. You should seesample.jpglisted. - Checkpoint 2: In your Rekognition JSON output, did you receive a list of
Labels? If you used a city image, you should see labels likeCity,Building, orUrban. - Checkpoint 3: In your Comprehend JSON output, locate the
SentimentScoreobject. Notice how the scores for Positive, Negative, Neutral, and Mixed all add up to approximately1.0(100%).
Concept Review
To solidify your understanding of Chapter 1, let's visually review the hierarchy of AI and the services you just used.
Terminology Mapping Table
| Textbook Concept | Lab Application | Description |
|---|---|---|
| Unstructured Data | sample.jpg, Raw Text | Data that does not fit neatly into rows and columns. |
| Inferencing | detect-labels, detect-sentiment | The process of passing new data through a trained model to make a prediction. |
| Real-time Inference | CLI Command Response | Receiving immediate, synchronous predictions with low latency. |
| Computer Vision | Amazon Rekognition | Deep learning applied to visual data extraction. |
| NLP | Amazon Comprehend | Deep learning applied to human language understanding. |
Clean-Up / Teardown
[!WARNING] Remember to run the teardown commands to avoid ongoing charges. While Rekognition and Comprehend charge per-request, S3 storage incurs ongoing costs.
Execute the following commands to delete the resources created in this lab:
# Empty the S3 bucket
aws s3 rm s3://brainybee-lab-vision-<YOUR_ACCOUNT_ID> --recursive
# Delete the S3 bucket
aws s3 rb s3://brainybee-lab-vision-<YOUR_ACCOUNT_ID>Note: Amazon Rekognition and Amazon Comprehend APIs used in this lab do not provision permanent infrastructure; they are stateless API calls.
Troubleshooting
| Error Message | Likely Cause | Solution |
|---|---|---|
AccessDenied | IAM User lacks permissions. | Ensure your IAM user has AmazonS3FullAccess, AmazonRekognitionFullAccess, and ComprehendFullAccess policies attached. |
BucketAlreadyExists | S3 bucket names are globally unique. | Change <YOUR_ACCOUNT_ID> to something highly unique (e.g., your name plus random numbers). |
InvalidImageFormatException | Rekognition doesn't support the file. | Ensure the image uploaded to S3 is a .jpg or .png file under 5MB. |
Could not connect to the endpoint URL | CLI region configuration issue. | Run aws configure and ensure you have a valid default region set (e.g., us-east-1). |
Stretch Challenge
Want to test your skills further without step-by-step guidance?
Challenge: Try passing an image containing printed text (like a picture of a street sign or a book page) to Amazon Rekognition to extract the words.
Hint: Look up the detect-text API method for Rekognition.
▶Show solution
# Upload an image with text first
aws s3 cp sign.jpg s3://brainybee-lab-vision-<YOUR_ACCOUNT_ID>/
# Run the detect-text API (Optical Character Recognition - OCR)
aws rekognition detect-text \
--image '{"S3Object":{"Bucket":"brainybee-lab-vision-<YOUR_ACCOUNT_ID>","Name":"sign.jpg"}}'