-
Notifications
You must be signed in to change notification settings - Fork 33
Review: AI/ML tutorials (batch 1) #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mwunderl
wants to merge
4
commits into
main
Choose a base branch
from
review/ai-ml-batch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Comprehend: Detect sentiment, entities, and key phrases | ||
|
|
||
| Analyze text using Amazon Comprehend's real-time APIs for language detection, sentiment analysis, entity recognition, key phrase extraction, and PII detection. | ||
|
|
||
| ## Source | ||
|
|
||
| https://docs.aws.amazon.com/comprehend/latest/dg/get-started-api.html | ||
|
|
||
| ## Use case | ||
|
|
||
| - ID: comprehend/getting-started | ||
| - Phase: create | ||
| - Complexity: beginner | ||
| - Core actions: comprehend:DetectSentiment, comprehend:DetectEntities, comprehend:DetectKeyPhrases | ||
|
|
||
| ## What it does | ||
|
|
||
| 1. Detects the dominant language of sample text | ||
| 2. Analyzes sentiment (positive, negative, neutral, mixed) | ||
| 3. Extracts named entities (people, organizations, dates) | ||
| 4. Extracts key phrases | ||
| 5. Detects PII entities (names, emails, phone numbers) | ||
|
|
||
| ## Running | ||
|
|
||
| ```bash | ||
| bash amazon-comprehend-gs.sh | ||
| ``` | ||
|
|
||
| ## Resources created | ||
|
|
||
| None. Comprehend is a stateless API. | ||
|
|
||
| ## Estimated time | ||
|
|
||
| - Run: ~5 seconds | ||
|
|
||
| ## Cost | ||
|
|
||
| Comprehend pricing is per unit (100 characters). This tutorial analyzes ~500 characters, costing less than $0.01. | ||
|
|
||
| ## Related docs | ||
|
|
||
| - [Real-time analysis with Amazon Comprehend](https://docs.aws.amazon.com/comprehend/latest/dg/get-started-api.html) | ||
| - [Sentiment analysis](https://docs.aws.amazon.com/comprehend/latest/dg/how-sentiment.html) | ||
| - [Entity recognition](https://docs.aws.amazon.com/comprehend/latest/dg/how-entities.html) | ||
| - [PII detection](https://docs.aws.amazon.com/comprehend/latest/dg/how-pii.html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Revision History: 090-amazon-comprehend-gs | ||
|
|
||
| ## Shell (CLI script) | ||
|
|
||
| ### 2026-04-14 v1 published | ||
| - Type: functional | ||
| - Initial version | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Detect sentiment, entities, and key phrases with Amazon Comprehend | ||
|
|
||
| This tutorial shows you how to use the Amazon Comprehend real-time analysis APIs to detect the dominant language, sentiment, entities, key phrases, and PII in text. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - AWS CLI configured with credentials and a default region | ||
| - Permissions to call Amazon Comprehend APIs | ||
|
|
||
| ## Step 1: Detect the dominant language | ||
|
|
||
| ```bash | ||
| aws comprehend detect-dominant-language --text "Your text here" \ | ||
| --query 'Languages[0].{Language:LanguageCode,Confidence:Score}' --output table | ||
| ``` | ||
|
|
||
| ## Step 2: Detect sentiment | ||
|
|
||
| ```bash | ||
| aws comprehend detect-sentiment --text "Your text here" --language-code en \ | ||
| --query '{Sentiment:Sentiment,Positive:SentimentScore.Positive,Negative:SentimentScore.Negative}' --output table | ||
| ``` | ||
|
|
||
| ## Step 3: Detect entities | ||
|
|
||
| Identifies people, places, organizations, dates, and other entity types. | ||
|
|
||
| ```bash | ||
| aws comprehend detect-entities --text "Your text here" --language-code en \ | ||
| --query 'Entities[].{Text:Text,Type:Type,Score:Score}' --output table | ||
| ``` | ||
|
|
||
| ## Step 4: Detect key phrases | ||
|
|
||
| ```bash | ||
| aws comprehend detect-key-phrases --text "Your text here" --language-code en \ | ||
| --query 'KeyPhrases[].{Text:Text,Score:Score}' --output table | ||
| ``` | ||
|
|
||
| ## Step 5: Detect PII entities | ||
|
|
||
| Identifies personally identifiable information such as names, email addresses, phone numbers, and account numbers. | ||
|
|
||
| ```bash | ||
| aws comprehend detect-pii-entities --text "Contact Jane at jane@example.com" --language-code en \ | ||
| --query 'Entities[].{Type:Type,Score:Score}' --output table | ||
| ``` | ||
|
|
||
| ## Cleanup | ||
|
|
||
| No cleanup needed. Comprehend is a stateless API — no resources are created. | ||
|
|
||
| The script automates all steps: | ||
|
|
||
| ```bash | ||
| bash amazon-comprehend-gs.sh | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/bin/bash | ||
| # Tutorial: Detect sentiment, entities, and key phrases with Amazon Comprehend | ||
| # Source: https://docs.aws.amazon.com/comprehend/latest/dg/get-started-api.html | ||
|
|
||
| WORK_DIR=$(mktemp -d) | ||
| LOG_FILE="$WORK_DIR/comprehend-$(date +%Y%m%d-%H%M%S).log" | ||
| exec > >(tee -a "$LOG_FILE") 2>&1 | ||
|
|
||
| REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null)}} | ||
| if [ -z "$REGION" ]; then | ||
| echo "ERROR: No AWS region configured. Set one with: export AWS_DEFAULT_REGION=us-east-1" | ||
| exit 1 | ||
| fi | ||
| export AWS_DEFAULT_REGION="$REGION" | ||
| echo "Region: $REGION" | ||
|
|
||
| TEXT="Amazon Comprehend is a natural language processing service that uses machine learning to find insights and relationships in text. The service can identify the language of the text, extract key phrases, places, people, brands, or events, and understand how positive or negative the text is." | ||
|
|
||
| echo "" | ||
| echo "Sample text:" | ||
| echo " $TEXT" | ||
| echo "" | ||
|
|
||
| # Step 1: Detect dominant language | ||
| echo "Step 1: Detecting dominant language" | ||
| aws comprehend detect-dominant-language --text "$TEXT" \ | ||
| --query 'Languages[0].{Language:LanguageCode,Confidence:Score}' --output table | ||
|
|
||
| # Step 2: Detect sentiment | ||
| echo "" | ||
| echo "Step 2: Detecting sentiment" | ||
| aws comprehend detect-sentiment --text "$TEXT" --language-code en \ | ||
| --query '{Sentiment:Sentiment,Positive:SentimentScore.Positive,Negative:SentimentScore.Negative,Neutral:SentimentScore.Neutral}' --output table | ||
|
|
||
| # Step 3: Detect entities | ||
| echo "" | ||
| echo "Step 3: Detecting entities" | ||
| aws comprehend detect-entities --text "$TEXT" --language-code en \ | ||
| --query 'Entities[].{Text:Text,Type:Type,Score:Score}' --output table | ||
|
|
||
| # Step 4: Detect key phrases | ||
| echo "" | ||
| echo "Step 4: Detecting key phrases" | ||
| aws comprehend detect-key-phrases --text "$TEXT" --language-code en \ | ||
| --query 'KeyPhrases[].{Text:Text,Score:Score}' --output table | ||
|
|
||
| # Step 5: Detect PII entities | ||
| echo "" | ||
| echo "Step 5: Detecting PII entities" | ||
| PII_TEXT="Please contact Jane Smith at jane.smith@example.com or call 555-0123. Her account number is 1234567890." | ||
| echo " PII sample: $PII_TEXT" | ||
| aws comprehend detect-pii-entities --text "$PII_TEXT" --language-code en \ | ||
| --query 'Entities[].{Type:Type,Score:Score}' --output table | ||
|
|
||
| echo "" | ||
| echo "Tutorial complete. No resources were created — Comprehend is a stateless API." | ||
| rm -rf "$WORK_DIR" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Translate: Translate text between languages | ||
|
|
||
| Translate text between languages using Amazon Translate, with auto-detection of the source language. | ||
|
|
||
| ## Source | ||
|
|
||
| https://docs.aws.amazon.com/translate/latest/dg/get-started.html | ||
|
|
||
| ## Use case | ||
|
|
||
| - ID: translate/getting-started | ||
| - Phase: create | ||
| - Complexity: beginner | ||
| - Core actions: translate:TranslateText, translate:ListLanguages | ||
|
|
||
| ## What it does | ||
|
|
||
| 1. Translates English text to Spanish | ||
| 2. Translates English text to French | ||
| 3. Translates English text to Japanese | ||
| 4. Auto-detects source language (German → English) | ||
| 5. Lists supported languages | ||
|
|
||
| ## Running | ||
|
|
||
| ```bash | ||
| bash amazon-translate-gs.sh | ||
| ``` | ||
|
|
||
| ## Resources created | ||
|
|
||
| None. Translate is a stateless API. | ||
|
|
||
| ## Estimated time | ||
|
|
||
| - Run: ~5 seconds | ||
|
|
||
| ## Cost | ||
|
|
||
| Translate pricing is per character. This tutorial translates ~600 characters, costing less than $0.01. | ||
|
|
||
| ## Related docs | ||
|
|
||
| - [Getting started with Amazon Translate](https://docs.aws.amazon.com/translate/latest/dg/get-started.html) | ||
| - [Translating text using the API](https://docs.aws.amazon.com/translate/latest/dg/get-started-api.html) | ||
| - [Supported languages](https://docs.aws.amazon.com/translate/latest/dg/what-is-languages.html) | ||
| - [Automatic source language detection](https://docs.aws.amazon.com/translate/latest/dg/auto-detect.html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Revision History: 091-amazon-translate-gs | ||
|
|
||
| ## Shell (CLI script) | ||
|
|
||
| ### 2026-04-14 v1 published | ||
| - Type: functional | ||
| - Initial version | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Translate text between languages with Amazon Translate | ||
|
|
||
| This tutorial shows you how to use Amazon Translate to translate text between languages, auto-detect the source language, and list supported languages. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - AWS CLI configured with credentials and a default region | ||
| - Permissions to call Amazon Translate APIs | ||
|
|
||
| ## Step 1: Translate English to Spanish | ||
|
|
||
| ```bash | ||
| aws translate translate-text \ | ||
| --text "Your text here" \ | ||
| --source-language-code en --target-language-code es \ | ||
| --query 'TranslatedText' --output text | ||
| ``` | ||
|
|
||
| ## Step 2: Translate English to French | ||
|
|
||
| ```bash | ||
| aws translate translate-text \ | ||
| --text "Your text here" \ | ||
| --source-language-code en --target-language-code fr \ | ||
| --query 'TranslatedText' --output text | ||
| ``` | ||
|
|
||
| ## Step 3: Translate English to Japanese | ||
|
|
||
| ```bash | ||
| aws translate translate-text \ | ||
| --text "Your text here" \ | ||
| --source-language-code en --target-language-code ja \ | ||
| --query 'TranslatedText' --output text | ||
| ``` | ||
|
|
||
| ## Step 4: Auto-detect source language | ||
|
|
||
| Use `auto` as the source language code to let Translate detect the language: | ||
|
|
||
| ```bash | ||
| aws translate translate-text \ | ||
| --text "Amazon Translate ist ein neuronaler maschineller Übersetzungsdienst." \ | ||
| --source-language-code auto --target-language-code en \ | ||
| --query '{Translation:TranslatedText,DetectedLanguage:SourceLanguageCode}' --output table | ||
| ``` | ||
|
|
||
| ## Step 5: List supported languages | ||
|
|
||
| ```bash | ||
| aws translate list-languages \ | ||
| --query 'Languages[:10].{Name:LanguageName,Code:LanguageCode}' --output table | ||
| ``` | ||
|
|
||
| ## Cleanup | ||
|
|
||
| No cleanup needed. Translate is a stateless API — no resources are created. | ||
|
|
||
| The script automates all steps: | ||
|
|
||
| ```bash | ||
| bash amazon-translate-gs.sh | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/bin/bash | ||
| # Tutorial: Translate text between languages with Amazon Translate | ||
| # Source: https://docs.aws.amazon.com/translate/latest/dg/get-started.html | ||
|
|
||
| WORK_DIR=$(mktemp -d) | ||
| LOG_FILE="$WORK_DIR/translate-$(date +%Y%m%d-%H%M%S).log" | ||
| exec > >(tee -a "$LOG_FILE") 2>&1 | ||
|
|
||
| REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null)}} | ||
| if [ -z "$REGION" ]; then | ||
| echo "ERROR: No AWS region configured. Set one with: export AWS_DEFAULT_REGION=us-east-1" | ||
| exit 1 | ||
| fi | ||
| export AWS_DEFAULT_REGION="$REGION" | ||
| echo "Region: $REGION" | ||
|
|
||
| TEXT="Amazon Translate is a neural machine translation service that delivers fast, high-quality, affordable, and customizable language translation." | ||
|
|
||
| echo "" | ||
| echo "Source text (English):" | ||
| echo " $TEXT" | ||
| echo "" | ||
|
|
||
| # Step 1: Translate English to Spanish | ||
| echo "Step 1: English → Spanish" | ||
| aws translate translate-text --text "$TEXT" \ | ||
| --source-language-code en --target-language-code es \ | ||
| --query 'TranslatedText' --output text | ||
| echo "" | ||
|
|
||
| # Step 2: Translate English to French | ||
| echo "Step 2: English → French" | ||
| aws translate translate-text --text "$TEXT" \ | ||
| --source-language-code en --target-language-code fr \ | ||
| --query 'TranslatedText' --output text | ||
| echo "" | ||
|
|
||
| # Step 3: Translate English to Japanese | ||
| echo "Step 3: English → Japanese" | ||
| aws translate translate-text --text "$TEXT" \ | ||
| --source-language-code en --target-language-code ja \ | ||
| --query 'TranslatedText' --output text | ||
| echo "" | ||
|
|
||
| # Step 4: Auto-detect source language | ||
| echo "Step 4: Auto-detect source language (German input)" | ||
| GERMAN="Amazon Translate ist ein neuronaler maschineller Übersetzungsdienst." | ||
| echo " Input: $GERMAN" | ||
| aws translate translate-text --text "$GERMAN" \ | ||
| --source-language-code auto --target-language-code en \ | ||
| --query '{Translation:TranslatedText,DetectedLanguage:SourceLanguageCode}' --output table | ||
| echo "" | ||
|
|
||
| # Step 5: List supported languages | ||
| echo "Step 5: Listing supported languages (first 10)" | ||
| aws translate list-languages --query 'Languages[:10].{Name:LanguageName,Code:LanguageCode}' --output table | ||
|
|
||
| echo "" | ||
| echo "Tutorial complete. No resources were created — Translate is a stateless API." | ||
| rm -rf "$WORK_DIR" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a more interesting example text