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

Add New API nn.HingeEmbeddingLoss #37540

Merged
merged 36 commits into from
Dec 15, 2021
Merged

Conversation

S-HuaBomb
Copy link
Contributor

PR types

New features

PR changes

APIs

Describe

Add HingeEmbeddingLoss, refer to torch.nn.HingeEmbeddingLoss

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@CLAassistant
Copy link

CLAassistant commented Nov 25, 2021

CLA assistant check
All committers have signed the CLA.

python/paddle/fluid/layers/loss.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/__init__.py Show resolved Hide resolved
python/paddle/nn/functional/loss.py Outdated Show resolved Hide resolved
python/paddle/fluid/layers/loss.py Outdated Show resolved Hide resolved
python/paddle/nn/functional/loss.py Outdated Show resolved Hide resolved
zhiboniu
zhiboniu previously approved these changes Nov 26, 2021
Copy link
Contributor

@zhiboniu zhiboniu left a 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/layer/loss.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/loss.py Outdated Show resolved Hide resolved
Ligoml
Ligoml previously approved these changes Nov 26, 2021
Copy link
Contributor

@Ligoml Ligoml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

TCChenlong
TCChenlong previously approved these changes Nov 29, 2021
Copy link
Contributor

@TCChenlong TCChenlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Ligoml Ligoml requested a review from zhiboniu December 7, 2021 06:13
# get wrong label elem not in {1., -1.}
self.wrong_label = paddle.randint(-3, 3, shape=self.shape)

def run_dynamic_check(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在可以支持静态图了,就也加上静态图的测试吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收到,

Done thanks.

'hinge_embedding_loss')

loss = paddle.where(label == 1., input, paddle.to_tensor(0.)) + \
paddle.where(label == -1., delta - input, paddle.to_tensor(0.))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max(0, delta-input)还是需要的吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,粗心了,已修改。

Done, thanks.

@S-HuaBomb S-HuaBomb changed the title Add loss Add New API nn.HingeEmbeddingLoss Dec 8, 2021
Ligoml
Ligoml previously approved these changes Dec 9, 2021
Copy link
Contributor

@Ligoml Ligoml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

zhiboniu
zhiboniu previously approved these changes Dec 10, 2021
Copy link
Contributor

@zhiboniu zhiboniu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

TCChenlong
TCChenlong previously approved these changes Dec 11, 2021
Copy link
Contributor

@TCChenlong TCChenlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

jeff41404
jeff41404 previously approved these changes Dec 13, 2021
Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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.
Copy link
Contributor

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

Copy link
Contributor Author

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 吗?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

辛苦改成margin吧,可以跟margin_ranking_loss保持一致

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

Copy link
Contributor

@Ligoml Ligoml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jeff41404 jeff41404 merged commit 3b85864 into PaddlePaddle:develop Dec 15, 2021
Caozhou1995 pushed a commit to Caozhou1995/Paddle that referenced this pull request Dec 29, 2021
* 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
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

Successfully merging this pull request may close these issues.

None yet

7 participants