ankane / torch.rb

Deep learning for Ruby, powered by LibTorch
Other
704 stars 30 forks source link

Docs: Warning on target size difference #47

Closed bockets closed 10 months ago

bockets commented 10 months ago

https://github.com/ankane/torch.rb/blob/b0fa9a17671e0b04e8529ea439601c831e087e3a/tutorials/blitz/neural_networks.md?plain=1#L143

I think this line is supposed to be target = Torch.randn(1, 10) rather than target = Torch.randn(10) to fit in with the sample code that precedes this line.

Otherwise I get the warning:

Using a target size ([10]) that is different to the input size ([1, 10]). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.

ankane commented 10 months ago

Hi @bockets, thanks for another report, but I'm not able to reproduce the warning. That line and the next one will give target a shape of [1, 10].

target = Torch.randn(10) # a dummy target, for example
target = target.view(1, -1) # make it the same shape as output