<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ayush Rastogi</title>
    <description>The latest articles on DEV Community by Ayush Rastogi (@erm0rden).</description>
    <link>https://dev.to/erm0rden</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F511788%2F3bf64d1e-87de-4146-92f4-70e0fb4a49be.jpg</url>
      <title>DEV Community: Ayush Rastogi</title>
      <link>https://dev.to/erm0rden</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/erm0rden"/>
    <language>en</language>
    <item>
      <title>Different ways of making REST Endpoint inference with Sagemaker SDK</title>
      <dc:creator>Ayush Rastogi</dc:creator>
      <pubDate>Mon, 02 May 2022 04:35:50 +0000</pubDate>
      <link>https://dev.to/erm0rden/different-ways-of-making-rest-endpoint-inference-with-sagemaker-sdk-241j</link>
      <guid>https://dev.to/erm0rden/different-ways-of-making-rest-endpoint-inference-with-sagemaker-sdk-241j</guid>
      <description>&lt;p&gt;In this article we are going to see two ways of making inference from a machine learning model endpoint using Sagemaker SDK. The machine learning model is trained on 'Amazon Customer Reviews Dataset' and can predict customer review rating on a scale of 1-5. As a part of transfer learning, I have used BERT model with pre-training carried out through DistilBERT, using Hugging face transformer, which provides bi-directional attention, and TensorFlow. Details regarding model implementation are shown below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3bRWUoM0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a33nn5ht66w13oocut9p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3bRWUoM0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a33nn5ht66w13oocut9p.png" alt="High-level ML model details" width="880" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first step for the inference script is to include the boiler plate details like session, bucket, role, region, account ID and Sagemaker object. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rxdUcijI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tb2ed8mluwyhxqt96hyt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rxdUcijI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tb2ed8mluwyhxqt96hyt.png" alt="Boiler plate Sagemaker setup code" width="550" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second step is to include the details completed during the model deployment stage. This will include the training job name, model name, and endpoint details. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CmSOLLIJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gnrfqwq4s0lxwuk4uq9m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CmSOLLIJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gnrfqwq4s0lxwuk4uq9m.png" alt="Retrieving model endpoint" width="429" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using the deployment stage details, a predictor object needs to be created which includes session details and the endpoint name. We are using JSONserializer and JSONdeserializer to format the input, interpret it and then deserialize it into an object type. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TvoQV28T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mgz8ydgw5qkn60ec2yi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TvoQV28T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mgz8ydgw5qkn60ec2yi.png" alt="Creating predictor object" width="429" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Category 1: Real-time/Ad-hoc predictions &lt;br&gt;
Once this predictor is created, it can be used to make ad-hoc predictions by providing inputs as features, shown below. Here function predictor.predict() is being used to make real-time predictions against Sagemaker endpoints with python objects. Four examples of Amazon reviews have been shown here. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ryOqQB60--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7t9bs32vfceh2uaq5hr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ryOqQB60--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7t9bs32vfceh2uaq5hr.png" alt="Real-time predictions" width="880" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Category 2: Batch predictions&lt;br&gt;
The reviews are stored in a .tsv file (tab separated value) and can be processed all at once. Predictions of 1000 sample reviews out of 102,084 reviews, were made which had a duration of 5 mins 45 seconds based on the compute being used. By providing the argument of 10, on the df_sample_reviews.head() call, we can retrieve the small number and validate the predictions. The column which serves as an input is 'review body' and predictions are compared against 'star rating'. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---KsORxkO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/op0a725lm27zki5hdhpb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---KsORxkO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/op0a725lm27zki5hdhpb.png" alt="Batch predictions" width="617" height="762"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Predictions can also be invoked model as a SageMaker Endpoint directly using the following HTTP request/response syntax. This approach is primarily being used when models are deployed as microservices in a production environment. &lt;/p&gt;

&lt;p&gt;References: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data Science on AWS, Chris Fregly and Antje Barth&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/index.html?nc2=h_ql_doc_do_v"&gt;https://docs.aws.amazon.com/index.html?nc2=h_ql_doc_do_v&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sagemaker.readthedocs.io/en/stable/"&gt;https://sagemaker.readthedocs.io/en/stable/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>sagemaker</category>
      <category>machinelearning</category>
      <category>rest</category>
    </item>
    <item>
      <title>Brief Intro to Services required for Sagemaker</title>
      <dc:creator>Ayush Rastogi</dc:creator>
      <pubDate>Sun, 01 May 2022 22:17:44 +0000</pubDate>
      <link>https://dev.to/erm0rden/brief-intro-to-services-required-for-sagemaker-4jbk</link>
      <guid>https://dev.to/erm0rden/brief-intro-to-services-required-for-sagemaker-4jbk</guid>
      <description>&lt;p&gt;In this article we are going to take a look at some of AWS services required for setup of AWS Sagemaker. Once you have an understanding of the services listed in this blog, you can start using sagemaker for machine learning. This will ensure you have a safe environment to provision AWS services and allow compute resources. Knowledge about some of these services is critical as it helps in determining the right decisions to comply with AWS shared responsibility model while taking security into consideration. The model is shown below.&lt;br&gt;
Some of the services we would need include: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;IAM account&lt;/li&gt;
&lt;li&gt;S3 bucket&lt;/li&gt;
&lt;li&gt;VPC &lt;/li&gt;
&lt;li&gt;EC2 instances. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XQ1O3nvL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgbc0vd64eylkwpa0tb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XQ1O3nvL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgbc0vd64eylkwpa0tb3.png" alt="AWS Shared Responsibility Model" width="880" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's go into the detail of what each service is and how it can be provisioned. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IAM (Identity and Access Management)&lt;/strong&gt;: This falls under 'security, identity and compliance' category under the AWS list of services. In order to access AWS services, you would need to provision IAM roles to gain and manage access to AWS resources. IAM policies are attached to specific roles, providing granular permissions and authentication to users, for specific services. IAM implements the concept of principals, actions, resources, and conditions. This defines which principals can perform which actions on which resources and under which conditions. Some of the most commonly used policy types include Identity based policies and resource based policies. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hlxT28IS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgtctrhroks59y4v60jd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hlxT28IS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgtctrhroks59y4v60jd.png" alt="AWS IAM" width="849" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;S3 (Simple Storage Service)&lt;/strong&gt; - This falls under 'storage' category under the AWS list of services. Amazon S3 is an object storage service and is used to store and protect any amount of data for a range of use cases, such as data lakes, websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics. Some of the features provided by S3 include different storage classes, storage and access management, data processing via s3 object lambda, as well as logging and monitoring tools. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UbQqnowj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wm9smffvo8dz675be4x6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UbQqnowj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wm9smffvo8dz675be4x6.png" alt="AWS S3" width="880" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;VPC (Virtual Private Cloud)&lt;/strong&gt; - To maintain security for data and applications, AWS resources are often provisioned inside a virtual network. Not only is it considered more secure, it can be managed according to an organization's requirements, providing more flexibility, while still keeping the benefits of using the scalable infrastructure of AWS. As an example, AWS resources like EC2 instances can be commissioned inside VPC, by specifying an IP address range for the VPC, and adding subnets, security groups and configuration of route tables. We can initiate a public subnet for access to the internet like cloning github repositories etc., whereas a private subnet can be utilized for sensitive data. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wCDtQrA7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7nwfc2395yb2d1ltv1ae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wCDtQrA7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7nwfc2395yb2d1ltv1ae.png" alt="Example of VPC" width="880" height="579"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Image Ref:   &lt;a href="https://www.geeksforgeeks.org/amazon-vpc-introduction-to-amazon-virtual-cloud/"&gt;https://www.geeksforgeeks.org/amazon-vpc-introduction-to-amazon-virtual-cloud/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EC2 (Elastic Compute Cloud)&lt;/strong&gt;: In order to perform any computations in the cloud, you would need a virtual computing environment and the service offered by AWS is EC2. Apart from being highly scalable, EC2 instances come in a variety of configurations of CPU, memory, storage, and networking capacity. Using a service like this would allow to remove any dependency and investments to on-premise hardware. Some compute examples are shown below. EC2 spot Instances can be utilized for various stateless, fault-tolerant, or flexible applications such as big data, containerized workloads, CI/CD, web servers, high-performance computing (HPC), and test &amp;amp; development workloads. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--98s5iPxO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b1q0fvmu9nufye71bcpt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--98s5iPxO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b1q0fvmu9nufye71bcpt.png" alt="EC2 Spot Instances" width="880" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7DiCZkgf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hd1lme4scw0p1kf0qa0d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7DiCZkgf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hd1lme4scw0p1kf0qa0d.png" alt="Some of the available instances in EC2" width="548" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: Image references from  &lt;a href="https://docs.aws.amazon.com/index.html"&gt;https://docs.aws.amazon.com/index.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>awscommunitybuilder</category>
      <category>sagemaker</category>
      <category>cloudcomputing</category>
    </item>
  </channel>
</rss>
