Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5cfc40de
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5cfc40de
编写于
1月 24, 2019
作者:
T
tangwei12
提交者:
GitHub
1月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
nce add check sample lables, test=develop (#15463)
* nce add check sample lables, test=develop
上级
af07118d
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
19 addition
and
5 deletion
+19
-5
paddle/fluid/operators/math/sampler.cc
paddle/fluid/operators/math/sampler.cc
+9
-1
paddle/fluid/operators/math/sampler.h
paddle/fluid/operators/math/sampler.h
+1
-0
paddle/fluid/operators/nce_op.h
paddle/fluid/operators/nce_op.h
+5
-0
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+4
-4
未找到文件。
paddle/fluid/operators/math/sampler.cc
浏览文件 @
5cfc40de
...
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/math/sampler.h"
#include <glog/logging.h>
#include <iostream>
#include <queue>
#include <utility>
...
...
@@ -77,7 +78,14 @@ int64_t CustomSampler::Sample() const {
auto
index
=
(
*
int_dist_
)(
*
random_engine_
);
auto
p
=
(
*
real_dist_
)(
*
random_engine_
);
if
(
p
>
alias_probs_
[
index
])
{
return
alias_
[
index
];
int
alias
=
alias_
[
index
];
if
(
alias
==
exceptional_val
)
{
LOG
(
WARNING
)
<<
"WARNING: CustomSampler get alias "
<<
exceptional_val
;
return
index
;
}
return
alias
;
}
else
{
return
index
;
}
...
...
paddle/fluid/operators/math/sampler.h
浏览文件 @
5cfc40de
...
...
@@ -116,6 +116,7 @@ class CustomSampler : public Sampler {
const
float
*
alias_probs_
;
const
int
*
alias_
;
const
float
*
probs_
;
const
int
exceptional_val
=
-
1
;
std
::
shared_ptr
<
std
::
mt19937
>
random_engine_
;
std
::
shared_ptr
<
std
::
uniform_real_distribution
<>>
real_dist_
;
std
::
shared_ptr
<
std
::
uniform_int_distribution
<>>
int_dist_
;
...
...
paddle/fluid/operators/nce_op.h
浏览文件 @
5cfc40de
...
...
@@ -119,6 +119,11 @@ class NCEKernel : public framework::OpKernel<T> {
PrepareSamples
<
DeviceContext
,
T
>
(
context
,
sampler
);
auto
sample_labels
=
context
.
Output
<
Tensor
>
(
"SampleLabels"
);
const
int64_t
*
sample_labels_data
=
sample_labels
->
data
<
int64_t
>
();
for
(
int
x
=
0
;
x
<
sample_labels
->
numel
();
x
++
)
{
PADDLE_ENFORCE_GE
(
sample_labels_data
[
x
],
0
,
"nce sample label %d"
,
x
);
}
auto
sample_out
=
context
.
Output
<
Tensor
>
(
"SampleLogits"
);
T
*
sample_out_data
=
sample_out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
label
=
context
.
Input
<
Tensor
>
(
"Label"
);
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
5cfc40de
...
...
@@ -5146,9 +5146,9 @@ def nce(input,
littles
=
[]
for
i
in
range
(
custom_dist_len
):
normal_prob
=
custom_dist
[
i
]
*
custom_dist_len
if
normal_prob
-
1.0
>
1e-4
:
if
normal_prob
-
1.0
>
0
:
bigs
.
append
((
i
,
normal_prob
))
elif
1.0
-
normal_prob
>
1e-4
:
elif
1.0
-
normal_prob
>
0
:
littles
.
append
((
i
,
normal_prob
))
else
:
alias_probs_
[
i
]
=
normal_prob
...
...
@@ -5164,9 +5164,9 @@ def nce(input,
alias_probs_
[
little
[
0
]]
=
little
[
1
]
alias_
[
little
[
0
]]
=
big_idx
big_left
=
big
[
1
]
+
little
[
1
]
-
1
if
big_left
-
1.0
>
1e-4
:
if
big_left
-
1.0
>
0
:
bigs
.
append
((
big_idx
,
big_left
))
elif
1.0
-
big_left
>
1e-4
:
elif
1.0
-
big_left
>
0
:
littles
.
append
((
big_idx
,
big_left
))
else
:
alias_probs_
[
big_idx
]
=
big_left
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录