Is it worth having a business account on TikTok?

I ask myself that same question everyday. For all you who are new to TikTok, get ready to be seduced by an endless barrage of seemingly random videos. And you can start right away; unlike Instagram…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




MLOps with AWS SageMaker

Amazon SageMaker is a fully-managed platform for building, training, and deploying machine learning models. The advantages of Amazon SageMaker include:

In this article, the details of these stages will be mentioned as an example.

BERT (Bidirectional Encoder Representations from Transformers) is a state-of-the-art pre-trained language model developed by Google. It uses a deep neural network with the Transformer architecture to perform a wide range of natural language processing tasks, such as text classification, question answering, and language translation, with high accuracy. The key innovation of BERT is that it uses a bidirectional training approach, which allows the model to consider the context of words in both directions (left and right) when making predictions, enabling it to better understand the context and meaning of words in a sentence. BERT has achieved state-of-the-art results on several benchmark datasets and is widely used in many NLP applications.

The original review text will be transformed into machine-readable features that can be utilized by BERT. To perform the required feature transformation you will configure an Amazon SageMaker processing job, which will be running a custom Python script.

Feature transformation in Amazon SageMaker refers to the process of converting raw input data into a format that is usable by machine learning algorithms. This process is an important step in the machine learning workflow, as raw input data is often in an unstructured format that cannot be directly used by machine learning algorithms. Feature transformation is used to extract meaningful features from the raw input data, such as text, images, or audio, and convert them into a numerical representation that can be used as input to the machine learning model.

Amazon SageMaker provides various feature transformation techniques, such as text vectorization, data normalization, and dimensionality reduction, as well as pre-built feature transformation algorithms, to make it easier for customers to preprocess their data and get started with building machine learning models. Additionally, Amazon SageMaker also provides the ability to create custom feature transformations using the SageMaker Processing feature.

Here are the steps involved in the feature transformation process on AWS:

Amazon SageMaker provides various pre-built feature transformation algorithms and the ability to create custom feature transformations using the SageMaker Processing feature, to make the feature transformation process easier for customers. Additionally, Amazon SageMaker integrates with other AWS services, such as Amazon S3 and Amazon EC2, to provide a scalable and secure environment for data processing and storage.

In this example, we will demonstrate how to train a natural language processing (NLP) classification problem using BERT and Amazon SageMaker. The training will be done using RoBERTa, a variant of BERT, within a PyTorch model run as a SageMaker Training Job. The steps involved in the analysis are:

We will utilize the “Bring Your Own Script” approach in this example.

Amazon SageMaker “Bring Your Own Script” scheme

The data has already been transformed and balanced into the format required by the model. Now, it needs to be copied to S3. The training and validation datasets will be used for training the model, while the test dataset will be reserved for future tuning purposes.

The PyTorch model will be prepared to function as a SageMaker Training Job in a standalone Python file, which will be invoked during the training process.

Training Jobs Metrics
Training Jobs Accuracy Line Graph

The process of deploying a model in Amazon SageMaker involves the following steps:

SageMaker makes the process of deploying and managing models as simple as possible, with built-in support for common use cases such as deploying to multiple regions, A/B testing, and canary deployments.

SageMaker Rest Endpoint
Test Model Results

In this part, we will do the following:

Overall Scheme of Pipeline
Bert Pipeline
Pipeline Artifacts
Test Model Results with Pipeline

Amazon SageMaker supports Automated Hyperparameter Tuning. It runs multiple training jobs on the training dataset using the hyperparameter ranges specified by the user. Then it chooses the combination of hyperparameters that leads to the best model candidate. The choice is made based on the objective metrics, e.g. maximization of the validation accuracy.

For the choice of hyperparameters combinations, SageMaker supports two different types of tuning strategies: random and Bayesian. This capability can be further extended by providing an implementation of a custom tuning strategy as a Docker container.

In this part we will perform the following three steps:

Overall Process of Hyperparameter Tuning Job
HPT Results
Confusion Matrix After HPT
5 Different Deployment Strategies

There are different options for deploying your models, but let’s now focus on some of the strategies to deploy new or updated models. This is important because we want to be able to deploy new models in a way that minimizes risk and downtime while measuring the performance of a new model or a new model version.

Let's start with blue/green deployments. Some of you may be familiar with the concept of blue/green deployments for applications or software. The same concept really applies to models as well. With blue/green deployments, you deploy your new model version to a stack that conserved prediction and response traffic coming into an endpoint. Then when you’re ready to have that new model version actually start to process prediction requests coming in, you swap the traffic to that new model version. This makes it easy to roll back because if there are issues with that new model or that new model version doesn’t perform well, you can swap traffic back to the previous model version.

Let’s now cover the second type of deployment strategy you see here called shadow or challenger deployment. This is often referred to as challenger models because in this case, you’re running a new model version in production by letting the new version accept prediction requests to see how that new model would respond, but you’re not actually serving the prediction response data from that new model version. This lets you validate the new model version with real traffic without impacting live prediction responses.

The next deployment strategy that we’ll cover is canary deployment. With a canary deployment, you split traffic between model versions and target a smaller group to expose that new model version 2. Typically, you’re exposing the select set of users to the new model for a smaller period of time to be able to validate the performance of that new model version before fully deploying that new version out to production. Canary deployment is a deployment strategy where you’re essentially splitting traffic between two model versions, and again, with canary deployments, you typically expose a smaller specific group to that new model version while model version 1 still serves the majority of your traffic.

The next deployment strategy is A/B testing. Canary and A/B testing are similar in that you’re splitting traffic. However, A/B testing is different in that typically you’re splitting traffic between larger groups and for longer periods of time to measure the performance of different model versions over time. This split can be done by targeting specific user groups or just by setting a percentage of traffic to randomly distribute to different groups.

All of the approaches that were covered are static approaches, meaning that you manually identify things like when to swap traffic and how to distribute that traffic. I’ll cover another approach that is more dynamic in nature, meaning that instead of manually identifying when and how you distribute traffic, you can take advantage of approaches that incorporate machine learning to automatically decide when and how to distribute traffic between multiple versions of a deployed model. For this, I’ll cover multi-armed bandits.

Multi-armed bandits use reinforcement learning as a way to dynamically shift traffic to the winning model versions by rewarding the winning model with more traffic but still exploring the nonwinning model versions in the case that those early winners were not the overall best models.

Endpoint Workflow

In this part, we will do the following:

1. Configure and create REST Enpoint with multiple variants

2. Test the model

3. Show the metrics for each variant

4. Shift all traffic to one variant

5. Configure one variant to autoscale

Traffic shifting and auto-scaling are both essential concepts in AWS for optimizing performance and cost efficiency.

Traffic shifting is the practice of gradually shifting traffic from one version of a service to another, allowing for a smooth transition and minimizing downtime. This can be achieved in AWS using services such as Elastic Load Balancing and AWS CodeDeploy. By gradually increasing traffic to a new version of a service and monitoring the results, you can quickly detect and resolve any issues that may arise, without disrupting users.

Auto-scaling, on the other hand, is the practice of automatically adjusting the number of instances in a service based on demand. This allows the service to handle increased traffic without manual intervention and reduces the risk of over-provisioning or under-provisioning instances. AWS offers several auto-scaling features, including Amazon EC2 Auto Scaling and Application Auto Scaling, which can be configured to automatically adjust the number of instances based on factors such as CPU utilization, network traffic, and other metrics.

By using traffic shifting and auto-scaling together, you can create a highly scalable and resilient system in AWS that can handle fluctuating traffic demands, without sacrificing performance or incurring unnecessary costs.

Endpoint Configuration

Now we will generate traffic. To analyze the endpoint performance you will review some of the metrics that Amazon SageMaker emits in CloudWatch: CPU Utilization, Latency and Invocations. Full list of namespaces and metrics can be found here: (https://docs.aws.amazon.com/sagemaker/latest/dg/monitoring-cloudwatch.html)

Endpoint Performance Metrics
Human-In-The-Loop Workflow

Data labeling is an essential step in building machine learning models, as labeled data is required for supervised learning. However, it can be a time-consuming and expensive process, particularly for complex datasets or specialized tasks. Amazon Augmented AI (A2I) is a service that helps to simplify the data labeling process, by allowing you to create and manage human review workflows, in combination with machine learning.

A2I enables you to add human review to your ML workflows using a set of pre-built templates or your own custom workflows. Once a model has made a prediction, A2I can route the prediction to human reviewers who can confirm or correct the prediction, providing feedback to the model to improve its accuracy. This human-in-the-loop approach can significantly reduce the time and cost of data labeling, while improving the quality of the labeled data.

A2I provides a wide range of options for setting up and managing human review workflows, including task types, worker pools, and pricing. You can use A2I for a variety of tasks, such as image or video classification, text transcription or translation, and more. A2I integrates with several other AWS services, including Amazon SageMaker and Amazon Rekognition, enabling you to build end-to-end ML solutions that include data labeling and human review.

Overall, A2I simplifies the process of data labeling and human review, allowing you to create high-quality datasets for training machine learning models, and providing a more accurate and efficient approach to building ML workflows.

The process can be summarized with the followings:

1. Setup private workforce and Cognito pool

2. Create the Human Task UI using a Worker Task Template

3. Create a Flow Definition

4. Start and check the status of the human loop

5. Verify the completion

6. View the labels and prepare data for training

Augmented AI

In conclusion, building a text classifier using Amazon SageMaker provides several advantages over traditional ML workflows. With SageMaker, you can easily train and deploy a text classifier model using state-of-the-art NLP models such as BERT, RoBERTa, or others, without having to worry about managing the underlying infrastructure. SageMaker provides pre-built algorithms, tools for monitoring and profiling the models, and a streamlined process for deploying the models as RESTful endpoints for real-time inferencing.

Using SageMaker also makes it easier to implement best practices for building and deploying NLP models, such as fine-tuning pre-trained models, using data pre-processing and feature engineering techniques, and setting up evaluation metrics.

Overall, Amazon SageMaker provides a comprehensive and scalable platform for building and deploying NLP models, making it an ideal choice for organizations looking to develop text classification applications.

Thanks for reading!

Add a comment

Related posts:

Tarot reading on Personal Growth.

The first card is The Tower, which represents a time of upheaval and change. This card suggests that you are currently facing a major shake-up in your life and may feel overwhelmed by the changes…