Skip to content

Commit 9cd5a15

Browse files
committed
fix the loss doc
1 parent 124484e commit 9cd5a15

17 files changed

+245
-748
lines changed

docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCELoss.md

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,65 +25,35 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
2525
| reduction | reduction | 表示应用于输出结果的计算方式。 |
2626

2727
### 转写示例
28-
29-
30-
#### size_average
31-
size_average 为 True
28+
#### reduction 为 sum
3229
```python
3330
# PyTorch 写法
34-
torch.nn.BCELoss(size_average=True)
31+
torch.nn.BCELoss(weight=w, size_average=False, reduce=True)
32+
torch.nn.BCELoss(weight=w, size_average=Flase)
3533

3634
# Paddle 写法
37-
paddle.nn.BCELoss(reduction='mean')
35+
paddle.nn.BCELoss(weight=w, reduction='sum')
3836
```
3937

40-
size_average 为 False
38+
#### reduction 为 mean
4139
```python
4240
# PyTorch 写法
43-
torch.nn.BCELoss(size_average=False)
41+
torch.nn.BCELoss(weight=w, size_average=True, reduce=True)
42+
torch.nn.BCELoss(weight=w, reduce=True)
43+
torch.nn.BCELoss(weight=w, size_average=True)
44+
torch.nn.BCELoss(weight=w)
4445

4546
# Paddle 写法
46-
paddle.nn.BCELoss(reduction='sum')
47+
paddle.nn.BCELoss(weight=w, reduction='mean')
4748
```
48-
#### reduce
49-
reduce 为 True
50-
```python
51-
# PyTorch 写法
52-
torch.nn.BCELoss(reduce=True)
5349

54-
# Paddle 写法
55-
paddle.nn.BCELoss(reduction='sum')
56-
```
57-
reduce 为 False
58-
```python
59-
# PyTorch 写法
60-
torch.nn.BCELoss(reduce=False)
61-
62-
# Paddle 写法
63-
paddle.nn.BCELoss(reduction='none')
64-
```
65-
#### reduction
66-
reduction 为'none'
67-
```python
68-
# PyTorch 写法
69-
torch.nn.BCELoss(reduction='none')
70-
71-
# Paddle 写法
72-
paddle.nn.BCELoss(reduction='none')
73-
```
74-
reduction 为'mean'
75-
```python
76-
# PyTorch 写法
77-
torch.nn.BCELoss(reduction='mean')
78-
79-
# Paddle 写法
80-
paddle.nn.BCELoss(reduction='mean')
81-
```
82-
reduction 为'sum'
50+
#### reduction 为 None
8351
```python
8452
# PyTorch 写法
85-
torch.nn.BCELoss(reduction='sum')
53+
torch.nn.BCELoss(weight=w, size_average=True, reduce=False)
54+
torch.nn.BCELoss(weight=w, size_average=False, reduce=False)
55+
torch.nn.BCELoss(weight=w, reduce=False)
8656

8757
# Paddle 写法
88-
paddle.nn.BCELoss(reduction='sum')
58+
paddle.nn.BCELoss(weight=w, reduction='None')
8959
```

docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCEWithLogitsLoss.md

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,65 +28,35 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
2828
| pos_weight | pos_weight | 表示正类的权重。 |
2929

3030
### 转写示例
31-
32-
33-
#### size_average
34-
size_average 为 True
31+
#### reduction 为 sum
3532
```python
3633
# PyTorch 写法
37-
torch.nn.BCEWithLogitsLoss(size_average=True)
34+
torch.nn.BCEWithLogitsLoss(weight=w, size_average=False, reduce=True)
35+
torch.nn.BCEWithLogitsLoss(weight=w, size_average=Flase)
3836

3937
# Paddle 写法
40-
paddle.nn.BCEWithLogitsLoss(reduction='mean')
38+
paddle.nn.BCEWithLogitsLoss(weight=w, reduction='sum')
4139
```
4240

43-
size_average 为 False
41+
#### reduction 为 mean
4442
```python
4543
# PyTorch 写法
46-
torch.nn.BCEWithLogitsLoss(size_average=False)
44+
torch.nn.BCEWithLogitsLoss(weight=w, size_average=True, reduce=True)
45+
torch.nn.BCEWithLogitsLoss(weight=w, reduce=True)
46+
torch.nn.BCEWithLogitsLoss(weight=w, size_average=True)
47+
torch.nn.BCEWithLogitsLoss(weight=w)
4748

4849
# Paddle 写法
49-
paddle.nn.BCEWithLogitsLoss(reduction='sum')
50+
paddle.nn.BCEWithLogitsLoss(weight=w, reduction='mean')
5051
```
51-
#### reduce
52-
reduce 为 True
53-
```python
54-
# PyTorch 写法
55-
torch.nn.BCEWithLogitsLoss(reduce=True)
5652

57-
# Paddle 写法
58-
paddle.nn.BCEWithLogitsLoss(reduction='sum')
59-
```
60-
reduce 为 False
61-
```python
62-
# PyTorch 写法
63-
torch.nn.BCEWithLogitsLoss(reduce=False)
64-
65-
# Paddle 写法
66-
paddle.nn.BCEWithLogitsLoss(reduction='none')
67-
```
68-
#### reduction
69-
reduction 为'none'
70-
```python
71-
# PyTorch 写法
72-
torch.nn.BCEWithLogitsLoss(reduction='none')
73-
74-
# Paddle 写法
75-
paddle.nn.BCEWithLogitsLoss(reduction='none')
76-
```
77-
reduction 为'mean'
78-
```python
79-
# PyTorch 写法
80-
torch.nn.BCEWithLogitsLoss(reduction='mean')
81-
82-
# Paddle 写法
83-
paddle.nn.BCEWithLogitsLoss(reduction='mean')
84-
```
85-
reduction 为'sum'
53+
#### reduction 为 None
8654
```python
8755
# PyTorch 写法
88-
torch.nn.BCEWithLogitsLoss(reduction='sum')
56+
torch.nn.BCEWithLogitsLoss(weight=w, size_average=True, reduce=False)
57+
torch.nn.BCEWithLogitsLoss(weight=w, size_average=False, reduce=False)
58+
torch.nn.BCEWithLogitsLoss(weight=w, reduce=False)
8959

9060
# Paddle 写法
91-
paddle.nn.BCEWithLogitsLoss(reduction='sum')
61+
paddle.nn.BCEWithLogitsLoss(weight=w, reduction='None')
9262
```

docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CosineEmbeddingLoss.md

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,65 +21,35 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
2121
| reduction | reduction | 指定应用于输出结果的计算方式。 |
2222

2323
### 转写示例
24-
25-
26-
#### size_average
27-
size_average 为 True
24+
#### reduction 为 sum
2825
```python
2926
# PyTorch 写法
30-
torch.nn.CosineEmbeddingLoss(size_average=True)
27+
torch.nn.CosineEmbeddingLoss(margin=m, size_average=False, reduce=True)
28+
torch.nn.CosineEmbeddingLoss(margin=m, size_average=Flase)
3129

3230
# Paddle 写法
33-
paddle.nn.CosineEmbeddingLoss(reduction='mean')
31+
paddle.nn.CosineEmbeddingLoss(margin=m, reduction='sum')
3432
```
3533

36-
size_average 为 False
34+
#### reduction 为 mean
3735
```python
3836
# PyTorch 写法
39-
torch.nn.CosineEmbeddingLoss(size_average=False)
37+
torch.nn.CosineEmbeddingLoss(margin=m, size_average=True, reduce=True)
38+
torch.nn.CosineEmbeddingLoss(margin=m, reduce=True)
39+
torch.nn.CosineEmbeddingLoss(margin=m, size_average=True)
40+
torch.nn.CosineEmbeddingLoss(margin=m)
4041

4142
# Paddle 写法
42-
paddle.nn.CosineEmbeddingLoss(reduction='sum')
43+
paddle.nn.CosineEmbeddingLoss(margin=m, reduction='mean')
4344
```
44-
#### reduce
45-
reduce 为 True
46-
```python
47-
# PyTorch 写法
48-
torch.nn.CosineEmbeddingLoss(reduce=True)
4945

50-
# Paddle 写法
51-
paddle.nn.CosineEmbeddingLoss(reduction='sum')
52-
```
53-
reduce 为 False
54-
```python
55-
# PyTorch 写法
56-
torch.nn.CosineEmbeddingLoss(reduce=False)
57-
58-
# Paddle 写法
59-
paddle.nn.CosineEmbeddingLoss(reduction='none')
60-
```
61-
#### reduction
62-
reduction 为'none'
63-
```python
64-
# PyTorch 写法
65-
torch.nn.CosineEmbeddingLoss(reduction='none')
66-
67-
# Paddle 写法
68-
paddle.nn.CosineEmbeddingLoss(reduction='none')
69-
```
70-
reduction 为'mean'
71-
```python
72-
# PyTorch 写法
73-
torch.nn.CosineEmbeddingLoss(reduction='mean')
74-
75-
# Paddle 写法
76-
paddle.nn.CosineEmbeddingLoss(reduction='mean')
77-
```
78-
reduction 为'sum'
46+
#### reduction 为 None
7947
```python
8048
# PyTorch 写法
81-
torch.nn.CosineEmbeddingLoss(reduction='sum')
49+
torch.nn.CosineEmbeddingLoss(margin=m, size_average=True, reduce=False)
50+
torch.nn.CosineEmbeddingLoss(margin=m, size_average=False, reduce=False)
51+
torch.nn.CosineEmbeddingLoss(margin=m, reduce=False)
8252

8353
# Paddle 写法
84-
paddle.nn.CosineEmbeddingLoss(reduction='sum')
54+
paddle.nn.CosineEmbeddingLoss(margin=m, reduction='None')
8555
```

docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CrossEntropyLoss.md

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,65 +36,36 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
3636
| - | axis | 进行 softmax 计算的维度索引,PyTorch 无此参数,Paddle 保持默认即可。 |
3737

3838
### 转写示例
39-
40-
41-
#### size_average
42-
size_average 为 True
43-
```python
44-
# PyTorch 写法
45-
torch.nn.CrossEntropyLoss(size_average=True)
46-
47-
# Paddle 写法
48-
paddle.nn.CrossEntropyLoss(reduction='mean')
49-
```
50-
51-
size_average 为 False
39+
#### reduction 为 sum
5240
```python
5341
# PyTorch 写法
54-
torch.nn.CrossEntropyLoss(size_average=False)
42+
torch.nn.CrossEntropyLoss(weight=w, size_average=False, reduce=True)
43+
torch.nn.CrossEntropyLoss(weight=w, size_average=Flase)
5544

5645
# Paddle 写法
57-
paddle.nn.CrossEntropyLoss(reduction='sum')
46+
paddle.nn.CrossEntropyLoss(weight=w, reduction='sum')
5847
```
59-
#### reduce
60-
reduce 为 True
61-
```python
62-
# PyTorch 写法
63-
torch.nn.CrossEntropyLoss(reduce=True)
6448

65-
# Paddle 写法
66-
paddle.nn.CrossEntropyLoss(reduction='sum')
67-
```
68-
reduce 为 False
49+
#### reduction 为 mean
6950
```python
7051
# PyTorch 写法
71-
torch.nn.CrossEntropyLoss(reduce=False)
52+
torch.nn.CrossEntropyLoss(weight=w, size_average=True, reduce=True)
53+
torch.nn.CrossEntropyLoss(weight=w, reduce=True)
54+
torch.nn.CrossEntropyLoss(weight=w, size_average=True)
55+
torch.nn.CrossEntropyLoss(weight=w)
7256

7357
# Paddle 写法
74-
paddle.nn.CrossEntropyLoss(reduction='none')
58+
paddle.nn.CrossEntropyLoss(weight=w, reduction='mean')
7559
```
76-
#### reduction
77-
reduction 为'none'
78-
```python
79-
# PyTorch 写法
80-
torch.nn.CrossEntropyLoss(reduction='none')
8160

82-
# Paddle 写法
83-
paddle.nn.CrossEntropyLoss(reduction='none')
84-
```
85-
reduction 为'mean'
61+
#### reduction 为 None
8662
```python
8763
# PyTorch 写法
88-
torch.nn.CrossEntropyLoss(reduction='mean')
64+
torch.nn.CrossEntropyLoss(weight=w, size_average=True, reduce=False)
65+
torch.nn.CrossEntropyLoss(weight=w, size_average=False, reduce=False)
66+
torch.nn.CrossEntropyLoss(weight=w, reduce=False)
8967

9068
# Paddle 写法
91-
paddle.nn.CrossEntropyLoss(reduction='mean')
69+
paddle.nn.CrossEntropyLoss(weight=w, reduction='None')
9270
```
93-
reduction 为'sum'
94-
```python
95-
# PyTorch 写法
96-
torch.nn.CrossEntropyLoss(reduction='sum')
9771

98-
# Paddle 写法
99-
paddle.nn.CrossEntropyLoss(reduction='sum')
100-
```

0 commit comments

Comments
 (0)