.sum(2, keepdim=True) means to perform the sum operation over the 2nd dimension. keepdim means that after reduction, that dimension remains but has size 1.
In [1]: import torch

In [2]: a = torch.rand(2, 3, 4)

In [3]: a.sum(2, keepdim=False).size()
Out[3]: torch.Size([2, 3])

In [4]: a.sum(2, keepdim=True).size()
Out[4]: torch.Size([2, 3, 1])