Solved by KFrank in post #2 
              
              
                Hello Anil! 

I prefer calculating the weight based on the entire dataset, 
rather than on a per-batch basis, although it shouldn’t matter 
if your batches are of reasonable size.  The point is that the 
weights aren’t magic numbers that have to be just right.  They 
are approximate numbers that are…