In this post, we will build a spam message classifier and deploy it. First, we will train and evaluate an Artificial Neural Network (ANN) model locally. Once we are satisfied with our model, we will deploy it on AWS using SageMaker.
This repository contains all the codes necessary to replicate the contents in this blog post. If you have any comments or suggestions, email me at [email protected].
Once we build a deep learning model using TensorFlow, we will deploy it on AWS using SageMaker. However, the version of SageMaker's TensorFlow is 1.15.5 at the time of this writing. This means that we have to use Python 3.7. For those of you who have Python 3.8 like me, it is important that we train the model using Python 3.7 in a virtual environment.
-
Type the following in Anaconda Prompt
"conda create -n python37 python=3.7" -
Activate the python37 virtual environment
"conda activate python37"
By the way, we can deactivate the virtual environment by typing "conda deactivate" but let's leave it active for now. -
Install necessary packages in the environment. For TensorFlow, let's match the version with SageMaker's version. pip install tensorflow==1.15.5 pip install pandas pip install matplotlib
-
Make the environment available in Jupyter Notebook
"pip install ipykernel"
"ipython kernel install --user --name=python37"
These will allow us to use the python37 kernel in Jupyter Notebook as shown below.
From the above image, click "python37" and create a new notebook using the virtual environment we just created.
Now we are ready to start working with data. Let's start writing in the spam_classifier.ipynb notebook.
- Create an AWS account
- Sign in
- Search S3 and go to Buckets
- Click the "create bucket" button in orange.
- Give it a name (e.g., spam-detector-s3) and select your region (I selected us-west-1)
- Click the name of the bucket to go into the bucket
- Upload "ann_model.zip" to the bucket
- Go to the SageMaker Dashboard by searching SageMaker.
- On the left menu, expand "notebook" and click instances.
- Click the "create notebook instance" button in orange.
- Give a name to the instance (I am calling it "spam-detector")
- The only other thing we need to set is "IAM role". Create one if you don't already have one.
- Leave all other settings as default and click the "create notebook instance" button in orange at the bottom.
- Click "Open Jupyter" to open Jupyter Notebook in SageMaker
- Create a new notebook by clicking "new" and selecting "conda_tensorflow_p36"
The remainder of this post will be explaining the deployment process in the notebook that we just created.
