Skip to main content
This lesson focuses on three practical problems you’ll often face when deploying ML in production:
  1. When to add a human in the loop for model inference (human review).
  2. How to create labeled training data at scale (data labeling).
  3. Providing a familiar R experience in the cloud (RStudio integration with SageMaker).
Each section below explains the problem, the managed SageMaker solution, and best-practice patterns you can adopt.

1) Human-in-the-loop: Why and when to involve people

Many applications require human validation of model predictions because of safety, fairness, or regulatory risk. Examples include medical imaging (false negatives are dangerous), loan approvals (regulatory and reputational risk), or high-value fraud decisions. Other common triggers for human review:
  • Low-confidence model outputs (e.g., confidence < configured threshold).
  • Compliance or audit requirements.
  • High-impact or ambiguous outcomes that demand human judgment.
A presentation slide titled "Problem: AI/ML Predictions Often Require Human Oversight" stating that many AI/ML applications need human review. It lists examples: sensitive decisions (e.g., medical diagnoses, loan approvals), low-confidence model predictions, and compliance/auditing requirements in regulated industries.
Humans-in-the-loop are appropriate when the cost of an incorrect automated decision is high or when regulations require an auditable human sign-off. You can combine ML confidence thresholds and business rules to automatically route ambiguous cases for review.

SageMaker Augmented AI (A2I)

SageMaker Augmented AI (A2I) is the managed AWS service for adding human review to inference workflows. Typical pattern:
  1. Model produces a prediction and an associated confidence score.
  2. If confidence is below a configured threshold (or a rule triggers), route the request into an A2I workflow.
  3. A2I presents the prediction and supporting context to a human reviewer and captures their response.
  4. The human decision is used to produce the final inference result.
You can choose built-in templates (e.g., image, document, text) or design custom reviewer UIs and quality controls. Who can perform reviews?
WorkforceUse case
Private (in-house) workforceSensitive data, internal audits, regulated industries
Amazon Mechanical TurkLarge-scale, on-demand labeling or review for low-sensitivity data
Third-party vendors via AWS MarketplaceOutsourced, specialized labeling providers with vetted security controls
A2I is suited to scenarios that require human validation for safety, legal, or business reasons. It provides routing control, reviewer UI configuration, and integration with a variety of workforces.
A presentation slide titled "Solution: Augmented AI (A2I)" that explains A2I as a way to add human review to ML workflows. Three highlighted points describe automated triggers for human review, custom/built-in workflows for document/image/NLP processing, and integration with Mechanical Turk or other workforces.

2) Labeling training data at scale

If your training dataset is not pre-labeled, you need a reliable, scalable labeling strategy. Manual labeling is expensive, slow, and prone to inconsistencies—especially at scale.
A presentation slide titled "Problem: Manual Data Labeling Is Costly and Error-Prone" that says "Labelling large datasets manually is:" and shows three icons labeled Expensive, Time-consuming, and Prone to human errors. The slide has a dark blue background and a small "© Copyright KodeKloud" note.

SageMaker Ground Truth

SageMaker Ground Truth coordinates human labelers, supplies UI templates and instructions, and offers automation/active-learning options to reduce cost and improve throughput. Labeling workflow overview:
  1. Create a labeling job with clear instructions and UI templates (classification, bounding boxes, segmentation, captions, etc.).
  2. Select the workforce (private, Mechanical Turk, or marketplace vendor).
  3. Aggregate outputs and apply quality controls (consensus, review, or automated checks).
Ground Truth reduces cost and increases throughput by enabling parallel annotation and by using automation where possible.
A screenshot of the "Solution: SageMaker Ground Truth" labeling interface, showing form fields to create an image caption. The task image displays a fluffy tan cat relaxing next to a large dog inside a house.

Ground Truth labeling modes

ModeDescriptionBest for
Human-onlyEvery item is labeled by human workersHigh-sensitivity or complex tasks
Human-in-the-loop (active learning)Ground Truth trains an incremental model from human labels and auto-labels easy cases, sending uncertain items to humansBalanced cost and quality
Fully automatedAutomated labeling without humansLow-risk, high-volume tasks where automation is reliable
Quality controls are essential. Use redundancy (multiple annotators per item), consensus algorithms, spot-check reviews, and clear instructions to reduce label noise and achieve consistent datasets.

3) RStudio in SageMaker Studio: enabling R workflows

Many data scientists prefer R and the RStudio IDE. Running RStudio in the cloud requires integration with enterprise networking, security, and shared data access. Manual setup can be time-consuming for teams.
A presentation slide titled "Problem: SageMaker Studio Application – RStudio" showing an illustrated data scientist at a laptop with charts and a clipboard labeled "DATA," alongside two R logos and the line "Many data scientists and statisticians use R and RStudio IDE."
Challenges include:
  • Installing and maintaining RStudio instances.
  • Secure networking and IAM-based authentication.
  • Collaboration and access to shared datasets.
A presentation slide titled "Problem: SageMaker Studio Application – RStudio" that lists three issues: setting up RStudio in the cloud is complex, it's difficult to ensure security and collaboration, and it requires manual configuration, networking, and authentication management. Icons and labels across the bottom highlight Manual configuration, Networking, and Authentication management.

Managed RStudio Workbench in SageMaker Studio

SageMaker Studio includes a managed RStudio Workbench (via Posit RStudio Workbench) that integrates with IAM, S3, and SageMaker training/inference. Users get the familiar multi-tab RStudio interface and can run R workflows without manual infrastructure setup.
A presentation slide titled "Solution: SageMaker Studio Application – RStudio" listing three points about a fully managed RStudio workbench integrated into SageMaker Studio, secure scalable collaborative cloud usage, and integration with AWS services. Icons for S3, SageMaker, and IAM appear across the bottom.
R users can run standard R workflows (preprocessing, training, saving artifacts) and also interoperate with Python-based SageMaker tooling.

Example: training with caret in R and saving artifacts

# Example R training snippet using caret
df_train_transformed <- predict(preProcValues, df_train)

# train a model on df_train_transformed
library(caret)
fitControl <- trainControl(
  method = "repeatedcv",
  number = 10,
  repeats = 10,
  classProbs = TRUE,
  summaryFunction = twoClassSummary
)

set.seed(825)
gbmFit <- train(
  Class ~ .,
  data = df_train_transformed[, 2:11],
  method = "gbm",
  trControl = fitControl,
  verbose = FALSE,   # passed through to the underlying method
  metric = "ROC"
)

print(gbmFit)

saveRDS(preProcValues, file = "./preProcessor.rds")
saveRDS(gbmFit, file = "./gbm_model.rds")
saveRDS(df_test[, 1:10], file = "./breast_cancer_test_data.rds")

Interoperability: calling the SageMaker Python SDK from R

Use the reticulate package to import Python modules and call the SageMaker Python SDK directly from RStudio. This allows R users to provision training jobs, endpoints, and other SageMaker resources from R.
# Example using reticulate to call the SageMaker Python SDK from R
library(reticulate)

sagemaker <- import("sagemaker")
Estimator <- sagemaker$estimator$Estimator

# Create a SageMaker Estimator via the Python SDK
est <- Estimator(
  image_uri = "123456789012.dkr.ecr.us-west-2.amazonaws.com/my-image:latest",
  role = "arn:aws:iam::123456789012:role/SageMakerRole",
  instance_count = 1L,
  instance_type = "ml.m5.large",
  sagemaker_session = sagemaker$Session()
)

# Start a training job (S3 path should contain training data)
est$fit("s3://my-bucket/my-training-data/")
Using reticulate provides the best of both worlds: RStudio as the native IDE for R users, and access to SageMaker’s Python SDK for orchestration.

Summary

This lesson covered three production concerns and the SageMaker solutions to address them:
  • Human-in-the-loop inference with SageMaker Augmented AI (A2I) — route low-confidence or regulated decisions for human review.
  • Scalable labeling with SageMaker Ground Truth — hybrid labeling, active learning, and automation to reduce cost and increase throughput.
  • Managed RStudio Workbench inside SageMaker Studio and Python interoperability via reticulate — enable R users to work securely and integrate with SageMaker services.
Additional references:

Watch Video