Giter VIP home page Giter VIP logo

mltrain-nips-2017's Issues

ComplementCrossEntropyLoss(torch.nn.Module)

Thanks for sharing your code, my question are:

  1. I'm confused of the function of ComplementCrossEntropyLoss? what's the difference between ComplementCrossEntropyLoss and nn.CrossEntropyLoss()
  2. In ComplementCrossEntropyLoss.py, when call for torch.nn.functional.nll_loss, why input is torch.log(1. - torch.nn.functional.softmax(input) + 1e-4)? what does 1- means?

class ComplementCrossEntropyLoss(torch.nn.Module):

Note: This is the cross entropy of the sum of all probabilities of other indices, except for the

This is used in Bayesian GAN semi-supervised learning

def init(self, except_index=None, weight=None, ignore_index=-100, size_average=True, reduce=True):
super(ComplementCrossEntropyLoss, self).init()
self.except_index = except_index
self.weight = weight
self.ignore_index = ignore_index
self.size_average = size_average
self.reduce = reduce

def forward(self, input, target=None):
# Use target if not None, else use self.except_index
if target is not None:
assert_no_grad(target)
else:
assert self.except_index is not None
target = torch.autograd.Variable(torch.LongTensor(input.data.shape[0]).fill
(self.except_index).cuda())
result = torch.nn.functional.nll_loss(
torch.log(1. - torch.nn.functional.softmax(input) + 1e-4),
target, weight=self.weight,
size_average=self.size_average,
ignore_index=self.ignore_index)
return result

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.