Exercise

# Calculating loss function in PyTorch

You are going to code the previous exercise, and make sure that we computed the loss correctly. Predicted scores are `-1.2`

for class `0`

(cat), `0.12`

for class `1`

(car) and `4.8`

for class `2`

(frog). The ground truth is class `2`

(frog). Compute the loss function in PyTorch.

Class | Predicted Score |
---|---|

Cat | -1.2 |

Car | 0.12 |

Frog | 4.8 |

Instructions

**100 XP**

- Initialize the tensor of scores with numbers
`[[-1.2, 0.12, 4.8]]`

, and the tensor of ground truth`[2]`

. - Instantiate the cross-entropy loss and call it
`criterion`

. - Compute and print the loss.