I saw you completely changed your question by editing it.
I almost missed that, it might have been better to post your new question below.



 jS5t3r:

The output is not that good… How can I improve the weights? Should I use the keywords reduce?


As it is now you are not doing anything inherently wrong. As long as the all_samples value is correct.
Take a look at this 14.
What reduction='none' changes compared to reduction='mean' (which is default), is that instead of getting the weighted mean of the output you will now get the output without any reduction applied, meaning you will get an output of the same size as the target size.
But keep in mind that, if you want to use the weight parameter of CELoss and set reduction to none, you would have to manually normalize your loss. See here 14.