pytorch / pytorch/pytorch.github.io
Incorrect code example in beginner tutorial (Build the Neural Network)
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 285
- Forks
- 317
- PR merge metrics
- No merged PRs in 30d
Description
📚 Documentation
Hey, I was following along the beginner tutorial and attempted to run the following code sample here:
https://pytorch.org/tutorials/beginner/basics/buildmodel_tutorial.html
X = torch.rand(1, 28, 28, device=device)
logits = model(X)
pred_probab = nn.Softmax(dim=1)(logits)
y_pred = pred_probab.argmax(1)
print(f"Predicted class: {y_pred}")
Running this example gave me the following RuntimeError
RuntimeError: The size of tensor a (28) must match the size of tensor b (784) at non-singleton dimension 2
After looking up the torch.rand docs https://pytorch.org/docs/stable/generated/torch.rand.html I attempted to change the parameters to something that seemed more correct considering the input tensor to the example NeuralNetwork class.
X = torch.rand(1, 28*28, device=device)
This seems to let the code example execute as expected (by the docs).
I will note however I am a TOTAL beginner here so if this isn't the right solution then please let me know!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the code sample in the linked Build the Neural Network beginner tutorial and reproduce the reported RuntimeError. Compare the sample input shape with the NeuralNetwork example and update the tutorial so the example runs successfully without the tensor-size error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100