SeriesAWS ML Engineer (Associate)4 / 9

SageMaker

Section 5 of AWS Certified ML Engineer course from Udemy.

Section 5 of AWS Certified Machine Learning Engineer Associate course from Udemy.

Introduction#

SageMaker offers many built-in algorithms for machine learning (ML) model training. This section covers the basics of SageMaker, as well as the various ML algorithms offered by the service.

SageMaker AI#

SageMaker is built to handle end-to-end ML workflows, including the core components of any ML project:

AWS SageMaker

Training and inference code is housed within separate Docker images within Amazon Elastic Container Registry (ECR). Given trained model object(s) in S3, SageMaker AI facilitates model hosting by spinning up HTTP endpoints as needed.

Working in SageMaker AI#

How can we actually train our models and perform experimentation? SageMaker Notebooks are EC2 instances which have access to S3, a wide variety of built-in ML models (provided via template Docker images), and many common ML programming libraries (e.g., scikit-learn, spark, tensorflow). While notebooks offer flexibility in terms of code, many of these same functionalities can be accomplished in the SageMaker Console.

Data is typically sourced from S3, but may also come from other services such as Athena, Elastic Map Reduce (EMR), Redshift, and so on. The ideal format for most ML algorithms is Protocol Buffers (Protobuf), which is Google’s open-source method for serializing structured data into a compact binary format.

Most actions in SageMaker are accomplished through the use of jobs:

Given a trained model stored in S3, there are two primary methods for Model Deployment:

Input Modes#

An Input Mode in SageMaker is a particular method for ingesting data as part of model training / inference. Different datasets may require different modes - for example, some ML training workflows involve massive datasets, whereas others are reasonably small and can fit in local memory. Modes provide alternative methods for data loading, enabling the user to make the most appropriate choice for their particular dataset and task.

Algorithms#

SageMaker offers a number of built-in algorithms to train ML models. This includes models for different categories of ML problems…

… which may be suited to different fields of application.

The following sections review some of the most popular ML algorithms available within SageMaker.

Supervised Learning#

Linear Learner#

Linear Learner is SageMaker’s algorithm for linear modeling, and may be applied to either classification or regression problems.

Linear Learner uses stochastic gradient descent to compute model parameters. The user may select one of many optimization algorithms (e.g., Adam vs. AdaGrad). Common hyperparameters include L1/L2 regularization coefficients, learning rate, multi-class weight balance, and so on.

XGBoost#

eXtreme Gradient Boosting (XGBoost) is a boosted ensemble of decision trees. In this context, boosting refers to iteratively training weak learners using a dynamically weighted data distribution, with higher priority given to misclassified instances. Similar to Linear Learner, XGBoost can be used for both classification and regression problems.

XGBoost has a wide range of hyperparameters, including:

LightGBM#

Light Gradient Boosting Machine (LightGBM) is another boosted ensemble of decision trees used for classification and regression problems. Its extensions to the standard boosting framework include gradient-based one-side sampling and exclusive feature bundling.

Common LightGBM hyperparameters include:

KNN#

K-Nearest Neighbors (KNN) is a relatively simple algorithm for classification or regression problems. The algorithm uses distance to identify the kk closest points to an instance, then predicts its label by returning the mode (classification) or average (regression) across this set.

In addition to the core algorithm, SageMaker includes a dimensionality reduction stage to avoid sparse data & the curse of dimensionality. The most important hyperparameter for KNN is kk - the number of neighbors to consider when computing a prediction.

Factorization Machines#

A Factorization Machine applies classification or regression to sparse data. It is commonly used for recommender systems, since a single user’s product interactions are likely sparse relative to a company’s entire set of offerings. Factorization is limited to pairwise interactions.

Important hyperparameters for factorization machines include bias, factors, and linear terms.

DeepAR#

Deep Autoregressive (DeepAR) uses RNNs to forecast one-dimensional time series data. This method is particularly useful for capturing frequency patterns and seasonality. DeepAR may be trained on multiple different time series, which may help to capture interdependent relationships between time series features.

Common DeepAR hyperparameters include:

Object2Vec#

Object2Vec creates a low-dimensional embedding given a high-dimensional instance (object). Object2Vec is essentially Word2Vec generalized to handle any object type (JSON; e.g., documents, IDs, sentence pairs, etc.). It is particularly useful as a preprocessing step for downstream ML applications.

In terms of architecture, Object2Vec has two separate input channels, each containing an encoder. The embedded values from each channel are concatenated and fed into a comparator network, which generates the final output.

AWS Object2Vec

Unsupervised Learning#

K-Means Clustering#

K-Means is an approach for clustering, which identifies similar groupings of instances within a dataset. In this context, similarity is defined in terms of distance.

AWS K Means

SageMaker extends the basic K-Means algorithm by starting with K=k×nK = k \times n clusters, then reducing clusters from KK to kk using Lloyd’s method. Extra cluster centers may help improve the algorithm’s fit.

PCA#

Principal Components Analysis (PCA) is a dimensionality reduction technique which projects higher-dimensional data into a lower-dimensional subspace while minimizing loss of information.

AWS PCA

PCA functions by performing singular value decomposition (SVD) on the covariance matrix of the dataset. SageMaker offers two modes for SVD: regular (for sparse data) and randomized (for large datasets; uses approximation approach).

Random Cut Forest#

Random Cut Forest is SageMaker’s algorithm for anomaly detection, which identifies unusual instances within a dataset. The algorithm functions by creating an ensemble of decision trees, with each tree representing a partition of the training data, then computing the expected change in tree complexity as a result of adding another data point.

Important hyperparameters for Random Cut Forest include:

IP Insights#

IP Insights is a tool used to flag suspicious behavior from IP addresses. It relies on an underlying neural network, which learns a latent vector representation of entities and IP addresses.

The primary hyperparameters for IP insights include the amount of entity vectors, vector dimensionality, and others generalizable across neural network training.

Textual Analysis#

Seq2Seq (Supervised)#

Sequence-to-Sequence (Seq2Seq) models generate an output sequence of tokens from an input sequence. This is particularly useful for NLP applications including machine translation, text summarization, and speech-to-text. Seq2Seq models are built on Recurrent Neural Networks (RNNs), Convolutional Neural Networks (CNNs), and/or the attention mechanism utilized in many deep learning techniques.

Due to their massive amount of parameters and training data size requirements, training deep learning models can take massive amounts of time and compute. SageMaker offers methods for fine-tuning via pre-trained foundation models, as well as public training datasets to facilitate common tasks.

Most Seq2Seq hyperparameters are generalizable to any neural network:

Seq2Seq models are optimized in terms of NLP evaluation metrics, which include accuracy, BLEU score, and perplexity.

BlazingText (Supervised & Unsupervised)#

BlazingText is an NLP tool which performs text classification and word embeddings. Text classification is a supervised learning task which predicts a label corresponding to a collection of words. Word2Vec creates a vector representation of a word to encode semantic meaning.

There are a few different training modes for Word2Vec.

Topic Modeling (Unsupervised)#

Topic Modeling automatically organizes documents into learned topics. SageMaker offers Neural Topic Modeling as one choice of algorithm; these approaches have some underlying deep learning component in their architecture. As part of neural topic modeling, the user specifies their desired number of topics. Topics themselves are a latent representation based on top-ranking words within a topic cluster.

Latent Dirichlet Allocation (LDA) is SageMaker’s other topic modeling algorithm, and is not based on deep learning. The primary hyperparameters for this algorithm are topic count and concentration (alpha0).

Image Processing#

Object Detection (Supervised)#

The goal of any Object Detection problem in computer vision is to identify all objects within an image, and designate them with bounding boxes. Object detection algorithms use a single deep neural network for both detection and classification, where classes are accompanied by probability (confidence) scores.

AWS Object Detection

Similar to other deep learning approaches in SageMaker, we have the option of training from scratch or using a pre-trained model based on some predefined neural architecture. For object detection, SageMaker supports:

Image Classification (Supervised)#

Whereas object detection identifies the bounding boxes for objects within an image, Image Classification is a similar computer vision technique which labels the object(s) present in an image. SageMaker supports separate algorithms for MXNet and TensorFlow.

Semantic Segmentation (Supervised)#

Semantic Segmentation is another computer vision technique which provides pixel-level object classification. The primary goal is to produce a segmentation mask to define regions of the image. Although this is a similar goal to object detection, semantic segmentation provides much more granular boundaries.

AWS Semantic Segmentation

SageMaker provides three different core algorithms for semantic segmentation:

In combination with these algorithms, SageMaker uses ResNet architecture pre-trained on the ImageNet dataset.


(all information obtained from AWS Certified Machine Learning Engineer Associate: Hands On! course on Udemy)

License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Related Posts