20.03.2021 Views

Deep-Learning-with-PyTorch

Create successful ePaper yourself

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

108 CHAPTER 5 The mechanics of learning

# In[2]:

t_c = [0.5, 14.0, 15.0, 28.0, 11.0, 8.0, 3.0, -4.0, 6.0, 13.0, 21.0]

t_u = [35.7, 55.9, 58.2, 81.9, 56.3, 48.9, 33.9, 21.8, 48.4, 60.4, 68.4]

t_c = torch.tensor(t_c)

t_u = torch.tensor(t_u)

Here, the t_c values are temperatures in Celsius, and the t_u values are our unknown

units. We can expect noise in both measurements, coming from the devices themselves

and from our approximate readings. For convenience, we’ve already put the

data into tensors; we’ll use it in a minute.

5.2.3 Visualizing the data

A quick plot of our data in figure 5.3 tells us that it’s noisy, but we think there’s a pattern

here.

25

temperature (°CELSIUS)

20

15

10

5

0

-5

20 30 40 50 60 70 80

measurement

Figure 5.3 Our unknown

data just might follow a

linear model.

NOTE Spoiler alert: we know a linear model is correct because the problem

and data have been fabricated, but please bear with us. It’s a useful motivating

example to build our understanding of what PyTorch is doing under the

hood.

5.2.4 Choosing a linear model as a first try

In the absence of further knowledge, we assume the simplest possible model for converting

between the two sets of measurements, just like Kepler might have done. The

two may be linearly related—that is, multiplying t_u by a factor and adding a constant,

we may get the temperature in Celsius (up to an error that we omit):

t_c = w * t_u + b

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

Saved successfully!

Ooh no, something went wrong!