I’m having trouble with the HingeEmbeddingLoss in pytorch 0.1.11.
When I try to specify the margin it throws an error.
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.
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.
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?
pass at line 220 should it not contain something like:
# Creates a criterion ...
def __init__(self, margin=1.0, size_average=True):
self.margin = margin
self.size_average = size_average
def forward(self, input1, target):
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: