-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add New API nn.HingeEmbeddingLoss #37540
Conversation
Thanks for your contribution! |
python/paddle/fluid/tests/unittests/test_hinge_embedding_loss.py
Outdated
Show resolved
Hide resolved
python/paddle/fluid/tests/unittests/test_hinge_embedding_loss.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
# get wrong label elem not in {1., -1.} | ||
self.wrong_label = paddle.randint(-3, 3, shape=self.shape) | ||
|
||
def run_dynamic_check(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在可以支持静态图了,就也加上静态图的测试吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
收到,
Done thanks.
python/paddle/nn/functional/loss.py
Outdated
'hinge_embedding_loss') | ||
|
||
loss = paddle.where(label == 1., input, paddle.to_tensor(0.)) + \ | ||
paddle.where(label == -1., delta - input, paddle.to_tensor(0.)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max(0, delta-input)还是需要的吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,粗心了,已修改。
Done, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
python/paddle/nn/functional/loss.py
Outdated
the shape is [N, \*], N is batch size and `\*` means any number of additional dimensions, available dtype is float32, float64. | ||
label (Tensor): Label tensor containing 1 or -1, the data type is float32 or float64. | ||
The shape of label is the same as the shape of input. | ||
delta (float, optional): Specifies the hyperparameter delta to be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确认下,这个参数名称用delta而不用margin的原因是什么?
在margin_ranking_loss这个api里是用margin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为公式里用 Δ 所以我就取名为 delta
。PyTorch 的同一个 API 也是用 margin,我要改成 margin 吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
辛苦改成margin吧,可以跟margin_ranking_loss保持一致
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks.
0391ff7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* add hinge_embedding_loss * fix test_API * test_API succeed * add English doc * fixed using of expired fluid api * fix doc * fix doc and rm python/paddle/fluid/layers/loss.py * get raw python/paddle/fluid/layers/loss.py back * fix Examples bug in English doc * unique -> flatten * fix api code * fix English doc * fix functional loss English doc * fix Example doc * .numpy() -> paddle.unique() * fix unique * fix label_item_set * modified judgment equation * Got a beautiful loss equation * use paddle.to_tensor * fix loss and add static check * fix loss and add static check * delta -> margin
PR types
New features
PR changes
APIs
Describe
Add HingeEmbeddingLoss, refer to torch.nn.HingeEmbeddingLoss