I have resolved the problem this way
def LogSoftmax(input,labels,ksi):
layer = torch.autograd.Variable(torch.empty(input.shape), requires_grad = True)
layer1 = layer.clone()
for j in range(input.shape[0]):
for i in range(input.shape[1]):
layer1[j,i] = torch.log(ksi[labels[j],i]*torch.exp(input[j,i])) - torch.log(sum([ksi[labels[j],k]*torch.exp(input[j,k]) for k in range(len(ksi))]))
return layer1