We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
RankHingeLoss的forward方法计算逻辑是:先计算负样本的cosine均值,再调用margin_ranking_loss计算loss。这样是不合理的,因为均值的margin_ranking_loss不等于margin_ranking_loss的均值。我尝试更改后,在模型效果上有很大提升。
def forward(self, y_pred: torch.Tensor, y_true: torch.Tensor): """ Calculate rank hinge loss. :param y_pred: Predicted result. :param y_true: Label. :return: Hinge loss computed by user-defined margin. """ y_pos = y_pred[::(self.num_neg + 1), :] y_neg = [] for neg_idx in range(self.num_neg): neg = y_pred[(neg_idx + 1)::(self.num_neg + 1), :] y_neg.append(neg) r = torch.mean(torch.stack([F.margin_ranking_loss(y_pos, neg, torch.ones_like(y_pos), margin=self.margin) for neg in y_neg])) return r
The text was updated successfully, but these errors were encountered:
@wenjunyang could you open a PR to fix the bug?
Sorry, something went wrong.
ok
No branches or pull requests
描述
RankHingeLoss的forward方法计算逻辑是:先计算负样本的cosine均值,再调用margin_ranking_loss计算loss。这样是不合理的,因为均值的margin_ranking_loss不等于margin_ranking_loss的均值。我尝试更改后,在模型效果上有很大提升。
fix后的参考代码
The text was updated successfully, but these errors were encountered: