Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results of LS #6

Closed
MrChenFeng opened this issue Aug 17, 2022 · 1 comment
Closed

Results of LS #6

MrChenFeng opened this issue Aug 17, 2022 · 1 comment

Comments

@MrChenFeng
Copy link

Thanks for your great work. The results of Labels moothing reported in your paper is surprisingly high. I wonder do you reproduce such results or copied from existing works? If former, could you share the code of it?

Thanks a lot!

@lgcnsai
Copy link
Owner

lgcnsai commented Oct 12, 2022

We reproduced all label-smoothing experiments, not copied from existing works.
This is the code that we are using.

`class CrossEntropyLabelSmooth(nn.Module):

def __init__(self, num_classes, epsilon=0.1):
	super(CrossEntropyLabelSmooth, self).__init__()
	self.num_classes = num_classes
	self.epsilon = epsilon
	self.logsoftmax = nn.LogSoftmax(dim=1).cuda()

def forward(self, inputs, targets):
	"""
	Args:
		inputs: prediction matrix (before softmax) with shape (batch_size, num_classes)
		targets: ground truth labels with shape (num_classes)
	"""
	log_probs = self.logsoftmax(inputs)
	targets = torch.zeros_like(log_probs).scatter_(1, targets.unsqueeze(1), 1)
	targets = (1 - self.epsilon) * targets + self.epsilon / self.num_classes
	loss = (- targets * log_probs).mean(0).sum()
	return loss`

@lgcnsai lgcnsai closed this as completed Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants