I’m having trouble with the HingeEmbeddingLoss in pytorch 0.1.11.
When I try to specify the margin it throws an error.
import torch
mrl = torch.nn.MarginRankingLoss(margin=0.5) # this works
hel = torch.nn.HingeEmbeddingLoss() # this works
# this throws an error - __init__() got an unexpected keyword argument margin
hel_m = torch.nn.HingeEmbeddingLoss(margin=0.5)
Looking at the source in nn/_functions/loss.py, it seems to be defined correctly.
Thanks
I think I got to the bottom of this. For some reason the HingeEmbeddingLoss class is not defined in: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/loss.py#L202
As opposed to MarginRankingLoss where the class is set up correctly: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/loss.py#L365
Not sure why though.
smth
April 27, 2017, 12:07am
3
smth
April 27, 2017, 12:09am
4
either ways this is fixed in master and will be part of next release.
Thanks for your response. I had a quick look at the master branch for loss.py but it has the same problem?
Instead of pass
at line 220 should it not contain something like:
class HingeEmbeddingLoss(_Loss):
# Creates a criterion ...
def __init__(self, margin=1.0, size_average=True):
super(HingeEmbeddingLoss, self).__init__()
self.margin = margin
self.size_average = size_average
def forward(self, input1, target):
return self._backend.HingeEmbeddingLoss(self.margin,
self.size_average)(input1, target)
smth
April 27, 2017, 8:36am
6
actually you’re right. this does give an error on master too. Needs to be fixed like you specified.
Can you send a pull request to patch this? thanks for finding the issue.
I made a pull request here:
pytorch:master
← macaodha:patch-1
opened 04:18PM - 27 Apr 17 UTC
Thanks