Adding a Dimension to a Tensor in PyTorch

Adding a dimension to a tensor can be important when you’re building deep learning models. In numpy, you can do this by inserting None into the axis you want to add.

import numpy as np

x1 = np.zeros((10, 10))
x2 = x1[None, :, :]
>>> print(x2.shape)
(1, 10, 10)
[Read More]

Sending a Text Message with SNS

SNS is AWS’s pub-sub service. It’s useful for sending and receiving alerts for events you care about. It can also be used to send SMS messages. If you’ve setup your AWS command-line tool, you can do this in 3 lines of Python.

import boto3
sns = boto3.client('sns')
   Message='hello world'
[Read More]

Some Cool IPython Tips

The IPython shell is a fast way to evaluate small bits of code. It also functions as a mighty fine calculator. You can install it with pip, pip install ipython, and launch it with the ipython command. Besides the normal Python REPL stuff, here are a few cool things about the IPython shell.


Let’s say you’re reading a blog post on how to do something amazing in Python and you want to follow along in the shell. If you copy a code snippet to your clipboard, you can type %paste in the shell and it will execute each line one at a time. Go ahead and try it:

one_string = "this "
two_string = "is "
red_string = "pretty "
blue_string = "sweet"
>>> %paste
>>> print(one_string + two_string + red_string + blue_string)
this is pretty sweet
[Read More]

PyTorch Quick Start: Classifying an Image

In this post we’ll classify an image with PyTorch. If you prefer to skip the prose, you can checkout the Jupyter notebook.

Two interesting features of PyTorch are pythonic tensor manipulation that’s similar to numpy and dynamic computational graphs, which handle recurrent neural networks in a more natural way than static computational graphs. A good description of the difference between dynamic and static graphs can be found here.

The most basic thing to do with a deep learning framework is to classify an image with a pre-trained model. This works out of the box with PyTorch.

[Read More]

AWS CLI Quick Start

The Amazon Web Services (AWS) command line tool is a full-featured alternative to using the AWS console to perform actions in your account. Getting started is dead simple.

I assume you have an AWS account and access to your Access Key ID and Secret Access Key.

  1. Install the tool.

    pip install awscli
  2. Add your credentials.

    aws configure

    Enter the AWS Access Key ID and AWS Secret Access Key when prompted. You’ll also need to set Default region name. I use us-east-1 for the region which is in Northern Virginia. This is a good region because all of the services are available there. It may be better to pick a different region if you live more than about 2,000 miles from Virginia.

[Read More]