{"id":1588,"date":"2022-02-23T23:41:16","date_gmt":"2022-02-23T23:41:16","guid":{"rendered":"https:\/\/salarydistribution.com\/machine-learning\/2022\/02\/23\/how-kustomer-utilizes-custom-docker-images-amazon-sagemaker-to-build-a-text-classification-pipeline\/"},"modified":"2022-02-23T23:41:16","modified_gmt":"2022-02-23T23:41:16","slug":"how-kustomer-utilizes-custom-docker-images-amazon-sagemaker-to-build-a-text-classification-pipeline","status":"publish","type":"post","link":"https:\/\/salarydistribution.com\/machine-learning\/2022\/02\/23\/how-kustomer-utilizes-custom-docker-images-amazon-sagemaker-to-build-a-text-classification-pipeline\/","title":{"rendered":"How Kustomer utilizes custom Docker images &amp; Amazon SageMaker to build a text classification pipeline"},"content":{"rendered":"<div id=\"\">\n<p><em>This is a guest post by Kustomer\u2019s Senior Software &amp; Machine Learning Engineer, Ian Lantzy, and AWS team Umesh Kalaspurkar, Prasad Shetty, and Jonathan Greifenberger.<\/em><\/p>\n<p>In Kustomer\u2019s own words,<em> \u201cKustomer is the omnichannel SaaS CRM platform reimagining enterprise customer service to deliver standout experiences. Built with intelligent automation, we scale to meet the needs of any contact center and business by unifying data from multiple sources and enabling companies to deliver effortless, consistent, and personalized service and support through a single timeline view.\u201d<\/em><\/p>\n<hr>\n<p>Kustomer wanted the ability to rapidly analyze large volumes of support communications for their business customers \u2014 customer experience and service organizations \u2014 and automate discovery of information such as the end-customer\u2019s intent, customer service issue, and other relevant insights related to the consumer. Understanding these characteristics can help CX organizations manage thousands of in-bound support emails by automatically classifying and categorizing the content. Kustomer leverages <a href=\"https:\/\/aws.amazon.com\/sagemaker\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SageMaker<\/a> to manage the analysis of the incoming support communications via their AI based <a href=\"https:\/\/www.kustomer.com\/product\/artificial-intelligence\/\" target=\"_blank\" rel=\"noopener noreferrer\">Kustomer IQ<\/a> platform. Kustomer IQ\u2019s Conversation Classification service is able to contextualize conversations and automate otherwise tedious and repetitive tasks, reducing agent distraction and the overall cost per contact. This and Kustomer\u2019s other IQ services have increased productivity and automation for its business customers.<\/p>\n<p>In this post, we talk about how Kustomer uses custom Docker images for SageMaker training and inference, which eases integration and streamlines the process. With this approach, Kustomer\u2019s business customers are automatically classifying over 50k support emails each month with up to 70% accuracy.<\/p>\n<h2>Background and challenges<\/h2>\n<p>Kustomer uses a custom text classification pipeline for their Conversation Classification service. This helps them manage thousands of requests a day via automatic classification and categorization utilizing SageMaker\u2019s training and inference orchestration. The Conversation Classification training engine uses custom Docker images to process data and train models using historical conversations and then predicts the topics, categories, or other custom labels a particular agent needs in order to classify the conversations. Then the prediction engine utilizes the trained models with another custom docker image to categorize conversations, which organizations use to automate reporting or route conversations to a specific team based on its topic.<\/p>\n<p>The SageMaker categorization process starts by establishing a training and inference pipeline that can provide text classification and contextual recommendations. A typical setup would be implemented with serverless approaches like <a href=\"https:\/\/aws.amazon.com\/lambda\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Lambda<\/a> for data preprocessing and postprocessing because it has a minimal provisioning requirement with an effective on-demand pricing model. However, using SageMaker with dependencies such as TensorFlow, NumPy, and Pandas can quickly increase the model package size, making the overall deployment process cumbersome and difficult to manage. Kustomer used custom Docker images to overcome these challenges.<\/p>\n<p>Custom Docker images provide substantial advantages:<\/p>\n<ul>\n<li>Allows for larger compressed package sizes (over 10 GB), which can contain popular machine learning (ML) frameworks such as TensorFlow, MXNet, PyTorch, or others.<\/li>\n<li>Allows you to bring custom code or algorithms developed locally to <a href=\"https:\/\/docs.aws.amazon.com\/sagemaker\/latest\/dg\/studio.html\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SageMaker Studio<\/a> notebooks for rapid iteration and model training.<\/li>\n<li>Avoids preprocessing delays caused in Lambda while unpacking deployment packages.<\/li>\n<li>Offers flexibility to integrate seamlessly with internal systems.<\/li>\n<li>Future compatibility and scalability make it easier to convert a service using Docker rather than having to package .zip files in a Lambda function.<\/li>\n<li>Reduces the turnaround time for a CI\/CD deployment pipeline.<\/li>\n<li>Provides Docker familiarity within the team and ease of use.<\/li>\n<li>Provides access to data stores via APIs and a backend runtime.<\/li>\n<li>Offers better support for intervening for any preprocessing or postprocessing that Lambda would require a separate compute service for each process (such as training or deployment).<\/li>\n<\/ul>\n<h2>Solution overview<\/h2>\n<p>Categorization and labeling of support emails is a critical step in the customer support process. It allows companies to route conversations to the right teams, and understand at a high level what their customers are contacting them about. Kustomer\u2019s business customers handle thousands of conversations every day, so classifying at scale is a challenge. Automating this process helps agents be more effective and provide more cohesive support, and helps their customers by connecting them with the right people faster.<\/p>\n<p>The following diagram illustrates the solution architecture:<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/ML-5601-image002.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-33115 size-full\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/ML-5601-image002.png\" alt=\"\" width=\"1265\" height=\"1287\"><\/a><\/p>\n<p>The Conversation Classification process starts with the business customer giving Kustomer permission to set up a training and inference pipeline that can help them with text classification and contextual recommendations. Kustomer exposes a user interface to their customers to monitor the training and inference process, which is implemented using SageMaker along with TensorFlow models and custom Docker images. The process of building and utilizing a classifier is split into five main workflows, which are coordinated by a worker service running on <a href=\"https:\/\/aws.amazon.com\/ecs\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon ECS<\/a>. To coordinate the pipeline events and trigger the training and deployment of the model, the worker uses an <a href=\"https:\/\/aws.amazon.com\/sqs\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SQS<\/a> queue and integrates directly with SageMaker using the AWS-provided Node.js SDK. The workflows are:<\/p>\n<ul>\n<li>Data export<\/li>\n<li>Data preprocessing<\/li>\n<li>Training<\/li>\n<li>Deployment<\/li>\n<li>Inference<\/li>\n<\/ul>\n<h3>Data export<\/h3>\n<p>The data export process is run on demand and starts with an approval process from Kustomer\u2019s business customer to confirm the use of email data for analysis. Data relevant to the classification process is captured via the initial email received from the end customer. For example, a support email typically contains the complete coherent thought of the problem with details about the issue. As part of the export process, the emails are collated from the data store (MongoDB and <a href=\"https:\/\/aws.amazon.com\/opensearch-service\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon OpenSearch<\/a>) and saved in <a href=\"http:\/\/aws.amazon.com\/s3\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Simple Storage Service<\/a> (Amazon S3).<\/p>\n<h3>Data preprocessing<\/h3>\n<p>The data preprocessing stage cleans the dataset for training and inference workflows by stripping any HTML tags from customer emails and feeding them through multiple cleaning and sanitization steps to detect any malformed HTML. This process includes the use of <a href=\"https:\/\/aws.amazon.com\/blogs\/machine-learning\/aws-and-hugging-face-collaborate-to-simplify-and-accelerate-adoption-of-natural-language-processing-models\/\" target=\"_blank\" rel=\"noopener noreferrer\">Hugging Face tokenizers and transformers<\/a>. When the cleansing process is complete, any additional custom tokens required for training are added to the output dataset.<\/p>\n<p>During the preprocessing stage, a Lambda function invokes a custom Docker image. This image consists of a Python 3.8 slim base, the <a href=\"https:\/\/pypi.org\/project\/awslambdaric\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Lambda Python Runtime Interface Client<\/a>, and dependencies such as <a href=\"https:\/\/numpy.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">NumPy<\/a> and <a href=\"https:\/\/pandas.pydata.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Pandas<\/a>. The custom Docker image is stored on <a href=\"http:\/\/aws.amazon.com\/ecr\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Elastic Container Registry<\/a> (Amazon ECR) and then fed through the CI\/CD pipeline for deployment. The deployed Lambda function samples the data to generate three distinct datasets per classifier:<\/p>\n<ul>\n<li><strong>Training<\/strong> \u2013 Used for the actual training process<\/li>\n<li><strong>Validation<\/strong> \u2013 Used for validation during the TensorFlow training process<\/li>\n<li><strong>Test<\/strong> \u2013 Used towards the end of the training process for metrics model comparisons<\/li>\n<\/ul>\n<p>The generated output datasets are Pandas pickle files, which are stored in Amazon S3 to be used by the training stage.<\/p>\n<h3>Training<\/h3>\n<p>Kustomer\u2019s custom training image utilizes a TensorFlow 2.7 GPU-optimized docker <a href=\"https:\/\/hub.docker.com\/layers\/tensorflow\/tensorflow\/2.4.1-gpu\/images\/sha256-03e706e09b0425bb4f634a644c5d869f3b6d6c027411ccca14c18719121d3064?context=explore\" target=\"_blank\" rel=\"noopener noreferrer\">image<\/a> as a base. Custom code, dependencies, and base models are included before the custom docker training image is uploaded to ECR. P3 instance types are used for the training process and using a GPU optimized base image helps to make the training process as efficient as possible. Amazon SageMaker is used with this custom docker image to train TensorFlow models that are then stored in S3. Custom metrics are also computed and saved to help with additional capabilities such as model comparisons and automatic retraining. Once the training stage is completed, the AI worker is notified and the business customer is able to start the deployment workflow.<\/p>\n<h3>Deployment<\/h3>\n<p>For the deployment workflow, a custom docker inference image is created using a TensorFlow serving base image (built specifically for fast inference). Additional code and dependencies like numPy, Pandas, custom NL, etc. are included to provide additional functionality, such as formatting &amp; cleaning inputs before inference. FastAPI is also included as part of the custom image, and is used to provide the REST API endpoints for inference and health checks. SageMaker is then configured to deploy the TensorFlow models saved in S3 with the inference image onto compute optimized ml.c5 AWS instances to generate high-performance inference endpoints. Each endpoint is created for use by a single customer to isolate their models and data.<\/p>\n<h3>Inference<\/h3>\n<p>Once the deployment workflow is completed, the inference workflow takes over. All first inbound support emails are passed through the inference API for the deployed classifiers specific to that customer. The deployed classifiers then perform text classification on each of these emails, each generating classification labels for the customer.<\/p>\n<h2>Possible enhancements and customizations<\/h2>\n<p>Kustomer is considering expanding the solution with the following enhancements:<\/p>\n<ul>\n<li><strong>Hugging Face DLCs<\/strong> \u2013 Kustomer currently uses TensorFlow\u2019s base Docker images for the data preprocessing stage and plans to migrate to <a href=\"https:\/\/aws.amazon.com\/about-aws\/whats-new\/2021\/07\/amazon-announces-new-aws-deep-learning-containers-to-deploy-hugging-face-models-faster-on-amazon-sagemaker\/\" target=\"_blank\" rel=\"noopener noreferrer\">Hugging Face Deep Learning Containers (DLCs)<\/a>. This helps you start training models immediately, skipping the complicated process of building and optimizing your training environments from scratch. For more information, see <a href=\"https:\/\/huggingface.co\/docs\/sagemaker\/main\" target=\"_blank\" rel=\"noopener noreferrer\">Hugging Face on Amazon SageMaker<\/a>.<\/li>\n<li><strong>Feedback loop <\/strong>\u2013 You can implement a feedback loop using active learning or reinforcement learning techniques to increase the overall efficiency of the model.<\/li>\n<li><strong>Integration with other internal systems <\/strong>\u2013 Kustomer wants the ability to integrate the text classification with other systems like Smart Suggestions, which is another Kustomer IQ service that looks through hundreds of shortcuts and suggest the shortcuts that are most relevant to a customer query, improving agent response times and performance.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>In this post, we discussed how Kustomer uses custom Docker images for SageMaker training and inference, which eases integration and streamlines the process. We demonstrated how Kustomer leverages Lambda and SageMaker with custom Docker images that help implement the text classification process with preprocessing and postprocessing workflows. This provides flexibility for using larger images for model creation, training, and inference. Container image support for Lambda allows you to customize your function even more, opening up many new use cases for serverless ML. The solution takes advantage of several AWS services, including SageMaker, Lambda, Docker images, Amazon ECR, Amazon ECS, Amazon SQS, and Amazon S3.<\/p>\n<p>If you want to learn more about Kustomer, we encourage you to visit the\u00a0<a href=\"https:\/\/www.kustomer.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Kustomer website<\/a> and explore their <a href=\"https:\/\/www.kustomer.com\/customers\/\" target=\"_blank\" rel=\"noopener noreferrer\">case studies.<\/a><\/p>\n<p>Click\u00a0<a href=\"https:\/\/aws.amazon.com\/sagemaker\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> to start your journey with Amazon SageMaker. For hands-on experience, you can reference the\u00a0Amazon SageMaker <a href=\"https:\/\/sagemaker-workshop.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">workshop.<\/a><\/p>\n<hr>\n<h3>About the Authors<\/h3>\n<p><strong> <a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/Umeshnk.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-33086 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/Umeshnk.jpg\" alt=\"\" width=\"100\" height=\"133\"><\/a> Umesh Kalaspurkar<\/strong> is a New York based Solutions Architect for AWS. He brings more than 20 years of experience in design and delivery of Digital Innovation and Transformation projects, across enterprises and startups. He is motivated by helping customers identify and overcome challenges. Outside of work, Umesh enjoys being a father, skiing, and traveling.<\/p>\n<p><strong><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/IanPicture.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-33087 size-full alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/IanPicture.jpg\" alt=\"\" width=\"100\" height=\"124\"><\/a>Ian Lantzy<\/strong> is a Senior Software &amp; Machine Learning engineer for Kustomer and specializes in taking machine learning research tasks and turning them into production services.<\/p>\n<p><strong><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/Prasad.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-33085 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/Prasad.jpg\" alt=\"\" width=\"100\" height=\"137\"><\/a>Prasad Shetty<\/strong> is a Boston-based Solutions Architect for AWS. He has built software products and has led modernizing and digital innovation in product and services across enterprises for over 20 years. He is passionate about driving cloud strategy and adoption, and leveraging technology to create great customer experiences. In his leisure time, Prasad enjoys biking and traveling.<\/p>\n<p><strong><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/Jonathan.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-33084 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/15\/Jonathan.jpg\" alt=\"\" width=\"100\" height=\"130\"><\/a>Jonathan Greifenberger\u00a0<\/strong>is a New York based Senior Account Manager for AWS with 25 years of IT industry experience. Jonathan leads a team that assists clients from various industries and verticals on their cloud adoption and modernization journey.<\/p>\n<p>       <!-- '\"` -->\n      <\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/aws.amazon.com\/blogs\/machine-learning\/how-kustomer-utilizes-custom-docker-images-amazon-sagemaker-to-build-a-text-classification-pipeline\/<\/p>\n","protected":false},"author":0,"featured_media":1589,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1588"}],"collection":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/comments?post=1588"}],"version-history":[{"count":0,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1588\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media\/1589"}],"wp:attachment":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media?parent=1588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/categories?post=1588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/tags?post=1588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}