It depends on the loss function you are using.
For a regression I would try nn.MSELoss, since you are dealing with float outputs.
The doc 11 states that the shape for the input as well as the target has to be (N, *), which means no broadcasting is needed.
For a classification use case, the loss functions indeed need another shaped target.
This is because in the most simple use case the NLLLoss needs an input of [batch_size, class_log_probabilities] and a target of [batch_size], where each entry stores the target class index.