Skip to main content
Stella Lin 님이 #Trailhead에 질문했습니다
Hi, I am working through the first hands-on exercises in Colaboratory for this module, and I am wondering if all of the exercises align with the Quiz questions in Trailhead for this module? I have completed the first four hands-on exercises in the Workbook_Deep_Learning_and_Natural_Language_Processing.ipynb in Colaboratory so far, and the output seems to align with the answers for the first four Quiz questions for this module, but the output I received for the fifth question does not, unless I am misunderstanding the instructions in the comments:

⌗ Set the seed for the random number generator for consistent,

⌗ reproducible results

torch.manual_seed(123)

⌗ initialize a tensor to be a sequence of numbers from 0 to 100 

⌗ and reshape it to be of size 2, 25, 2

x = torch.arange(start=0, end=100).reshape(2, 25, 2)

⌗ TODO: Print the sum of x over dimension 1

⌗ (https://pytorch.org/docs/stable/torch.html⌗comparison-ops)

⌗ note that the max over a dimension will return the indices of the maximum

⌗ values as well. We only want the maximum values.

print('Answer: ', torch.cumsum(x,1) ) 

I read about the cumsum function from the link given in the previous section to https://pytorch.org/docs/stable/torch.html⌗reduction-ops, but is there another function that I should be using, instead, from the https://pytorch.org/docs/stable/torch.html⌗comparison-ops section that would give a result containing only two elements similar to the questions for this next Quiz question in the corresponding Trailhead module?  The output I received is similar to the output in this example from the PyTorch documentation for the cumsum function:

torch.cumsum(input, dim, out=None, dtype=None) → Tensor

Returns the cumulative sum of elements of input in the dimension dim.

For example, if input is a vector of size N, the result will also be a vector of size N, with elements.

y_i = x_1 + x_2 + x_3 + \dots + x_iyi​=x1​+x2​+x3​+⋯+xi​

Parameters:input (Tensor) – the input tensor

dim (int) – the dimension to do the operation over

dtype (torch.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: None.

Example:

>>> a = torch.randn(10) >>> a tensor([-0.8286, -0.4890, 0.5155, 0.8443, 0.1865, -0.1752, -2.0595, 0.1850, -1.1571, -0.4243]) >>> torch.cumsum(a, dim=0) tensor([-0.8286, -1.3175, -0.8020, 0.0423, 0.2289, 0.0537, -2.0058, -1.8209, -2.9780, -3.4022])

 
답변 2개
  1. 2019년 6월 16일 오전 3:16

    Dear Brett,

    It has been a while since I have been in Colaboratory, and I am having some trouble re-opening (or even uploading a new copy) of the notebook for this module, but I wanted to let you know that I appreciate your response, and that it makes sense in PyTorch!

    Best,

    Stella Lin

0/9000