22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A Note on Notation

So far, we’ve handled either one feature (up to Chapter 2) or two features

(this chapter). It has allowed us to spell equations out, listing all terms.

But the number of features will soon increase quickly when we tackle images

as inputs. So we need to agree on notation for vectorized features. Actually,

I already used it in Figure 3.5 above.

The vectorized representations of the weights (W) and features (X) are:

I will always place the dimensions below the vectors to make it more clear.

The logits (z), as shown in Figure 3.5, are given by the expression below:

From now on, instead of using the final and long expression, we’ll use the first

and more concise one.

Now let’s use the Sequential model to build our logistic regression in PyTorch:

torch.manual_seed(42)

model1 = nn.Sequential()

model1.add_module('linear', nn.Linear(2, 1))

model1.add_module('sigmoid', nn.Sigmoid())

print(model1.state_dict())

220 | Chapter 3: A Simple Classification Problem

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!