Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
4b1b599a
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4b1b599a
编写于
4月 10, 2017
作者:
Y
Yu Yang
提交者:
GitHub
4月 10, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1762 from reyoung/feature/refine_nce_layer
Refine NCE Layer
上级
7e6def58
7adad0c9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
6 deletion
+18
-6
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+18
-6
未找到文件。
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
4b1b599a
...
@@ -18,7 +18,7 @@ import inspect
...
@@ -18,7 +18,7 @@ import inspect
from
paddle.trainer.config_parser
import
*
from
paddle.trainer.config_parser
import
*
from
.activations
import
LinearActivation
,
SigmoidActivation
,
TanhActivation
,
\
from
.activations
import
LinearActivation
,
SigmoidActivation
,
TanhActivation
,
\
ReluActivation
,
IdentityActivation
,
SoftmaxActivation
ReluActivation
,
IdentityActivation
,
SoftmaxActivation
,
BaseActivation
from
.evaluators
import
*
from
.evaluators
import
*
from
.poolings
import
MaxPooling
,
AvgPooling
,
BasePoolingType
from
.poolings
import
MaxPooling
,
AvgPooling
,
BasePoolingType
from
.attrs
import
*
from
.attrs
import
*
...
@@ -2253,8 +2253,9 @@ def img_pool_layer(input,
...
@@ -2253,8 +2253,9 @@ def img_pool_layer(input,
pool_type
.
name
=
'avg'
pool_type
.
name
=
'avg'
type_name
=
pool_type
.
name
+
'-projection'
\
type_name
=
pool_type
.
name
+
'-projection'
\
if
(
isinstance
(
pool_type
,
AvgPooling
)
or
isinstance
(
pool_type
,
MaxPooling
))
\
if
(
else
pool_type
.
name
isinstance
(
pool_type
,
AvgPooling
)
or
isinstance
(
pool_type
,
MaxPooling
))
\
else
pool_type
.
name
pool_size_y
=
pool_size
if
pool_size_y
is
None
else
pool_size_y
pool_size_y
=
pool_size
if
pool_size_y
is
None
else
pool_size_y
stride_y
=
stride
if
stride_y
is
None
else
stride_y
stride_y
=
stride
if
stride_y
is
None
else
stride_y
...
@@ -3294,8 +3295,8 @@ def recurrent_group(step,
...
@@ -3294,8 +3295,8 @@ def recurrent_group(step,
assert
(
targetInlink
==
None
or
targetInlink_in_inlinks
())
assert
(
targetInlink
==
None
or
targetInlink_in_inlinks
())
targetInlinkName
=
None
if
targetInlink
==
None
\
targetInlinkName
=
None
if
targetInlink
==
None
\
else
targetInlink
.
name
if
isinstance
(
targetInlink
,
LayerOutput
)
\
else
targetInlink
.
name
if
isinstance
(
targetInlink
,
LayerOutput
)
\
else
targetInlink
.
input
.
name
else
targetInlink
.
input
.
name
contains_sub_seq
=
[
False
]
contains_sub_seq
=
[
False
]
...
@@ -4807,12 +4808,14 @@ def crf_decoding_layer(input,
...
@@ -4807,12 +4808,14 @@ def crf_decoding_layer(input,
return
LayerOutput
(
name
,
LayerType
.
CRF_DECODING_LAYER
,
parents
,
size
=
1
)
return
LayerOutput
(
name
,
LayerType
.
CRF_DECODING_LAYER
,
parents
,
size
=
1
)
@
wrap_act_default
(
act
=
SigmoidActivation
())
@
wrap_bias_attr_default
(
has_bias
=
True
)
@
wrap_bias_attr_default
(
has_bias
=
True
)
@
wrap_name_default
()
@
wrap_name_default
()
@
layer_support
()
@
layer_support
()
def
nce_layer
(
input
,
def
nce_layer
(
input
,
label
,
label
,
num_classes
,
num_classes
,
act
=
None
,
weight
=
None
,
weight
=
None
,
num_neg_samples
=
10
,
num_neg_samples
=
10
,
neg_distribution
=
None
,
neg_distribution
=
None
,
...
@@ -4841,6 +4844,8 @@ def nce_layer(input,
...
@@ -4841,6 +4844,8 @@ def nce_layer(input,
:type weight: LayerOutput
:type weight: LayerOutput
:param num_classes: number of classes.
:param num_classes: number of classes.
:type num_classes: int
:type num_classes: int
:param act: Activation, default is Sigmoid.
:type act: BaseActivation
:param num_neg_samples: number of negative samples. Default is 10.
:param num_neg_samples: number of negative samples. Default is 10.
:type num_neg_samples: int
:type num_neg_samples: int
:param neg_distribution: The distribution for generating the random negative labels.
:param neg_distribution: The distribution for generating the random negative labels.
...
@@ -4863,6 +4868,8 @@ def nce_layer(input,
...
@@ -4863,6 +4868,8 @@ def nce_layer(input,
assert
isinstance
(
neg_distribution
,
collections
.
Sequence
)
assert
isinstance
(
neg_distribution
,
collections
.
Sequence
)
assert
len
(
neg_distribution
)
==
num_classes
assert
len
(
neg_distribution
)
==
num_classes
assert
sum
(
neg_distribution
)
==
1
assert
sum
(
neg_distribution
)
==
1
if
not
isinstance
(
act
,
BaseActivation
):
raise
TypeError
()
ipts_for_layer
=
[]
ipts_for_layer
=
[]
parents
=
[]
parents
=
[]
...
@@ -4884,12 +4891,17 @@ def nce_layer(input,
...
@@ -4884,12 +4891,17 @@ def nce_layer(input,
type
=
LayerType
.
NCE_LAYER
,
type
=
LayerType
.
NCE_LAYER
,
num_classes
=
num_classes
,
num_classes
=
num_classes
,
neg_sampling_dist
=
neg_distribution
,
neg_sampling_dist
=
neg_distribution
,
active_type
=
act
.
name
,
num_neg_samples
=
num_neg_samples
,
num_neg_samples
=
num_neg_samples
,
inputs
=
ipts_for_layer
,
inputs
=
ipts_for_layer
,
bias
=
ParamAttr
.
to_bias
(
bias_attr
),
bias
=
ParamAttr
.
to_bias
(
bias_attr
),
**
ExtraLayerAttribute
.
to_kwargs
(
layer_attr
))
**
ExtraLayerAttribute
.
to_kwargs
(
layer_attr
))
return
LayerOutput
(
return
LayerOutput
(
name
,
LayerType
.
NCE_LAYER
,
parents
=
parents
,
size
=
l
.
config
.
size
)
name
,
LayerType
.
NCE_LAYER
,
parents
=
parents
,
size
=
l
.
config
.
size
,
activation
=
act
)
"""
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录