Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
a25c3aeb
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a25c3aeb
编写于
11月 17, 2017
作者:
Y
Yancey1989
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add forward
上级
695b1037
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
11 deletion
+28
-11
paddle/operators/hierarchical_sigmoid_op.cc
paddle/operators/hierarchical_sigmoid_op.cc
+6
-7
paddle/operators/hierarchical_sigmoid_op.h
paddle/operators/hierarchical_sigmoid_op.h
+15
-1
paddle/operators/math/matrix_bit_code.cc
paddle/operators/math/matrix_bit_code.cc
+3
-3
paddle/operators/math/matrix_bit_code.h
paddle/operators/math/matrix_bit_code.h
+4
-0
未找到文件。
paddle/operators/hierarchical_sigmoid_op.cc
浏览文件 @
a25c3aeb
...
...
@@ -83,19 +83,18 @@ class HierarchicalSigmoidOpMaker : public framework::OpProtoAndCheckerMaker {
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"(TensorArray, required) The input array. Each Tensor has the "
"same shape with [N * D]."
.
AsDuplicable
();
"same shape with [N * D]."
)
.
AsDuplicable
();
AddInput
(
"Label"
,
"(Tensor, required), The labels of training data. It's a"
"1-D tensor."
);
AddInput
(
"Bias"
,
"(Tensor, optional), The bias is a 1-D tensor, "
"which is applied to the output"
);
AddOutput
(
"Out"
,
"(Tensor, required) The output of hierarchical sigmoid operator."
);
AddAttr
<
int
>
(
"num_classes"
,
"(int, required)"
,
"The number of classes"
);
AddOutput
(
"Out"
,
"(Tensor, required) The output of hierarchical sigmoid operator."
);
AddAttr
<
int
>
(
"num_classes"
,
"(int, required)"
,
"The number of classes"
);
AddComment
(
R"DOC(
The hierarchical sigmoid operator organize the classes into a binary tree.
At each node, a sigmoid function is used to caculate the probability of
...
...
paddle/operators/hierarchical_sigmoid_op.h
浏览文件 @
a25c3aeb
...
...
@@ -22,7 +22,21 @@ template <typename Place, typename T>
class
HierarchicalSigmoidOpKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{}
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
ins
=
ctx
.
MultiInput
<
framework
::
Tensor
>
(
"X"
);
auto
*
label
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Label"
);
auto
*
bias
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Bias"
);
size_t
num_classes
=
static_cast
<
size_t
>
(
ctx
.
Attr
<
int
>
(
"num_classes"
));
int64_t
batch_size
=
ins
[
0
]
->
dims
()[
0
];
int64_t
size
=
ins
.
size
();
framework
::
Tensor
pre_out
;
std
::
vector
<
int64_t
>
pre_out_dims
({
batch_size
,
size
});
pre_out
.
mutable_data
<
T
>
(
framework
::
make_ddim
(
pre_out_dims
),
ctx
.
GetPlace
());
if
(
bias
!=
NULL
)
{
math
::
AddByBitCode
<
T
>
(
num_classes
,
*
label
,
pre_out
,
*
bias
);
}
}
};
template
<
typename
Place
,
typename
T
>
...
...
paddle/operators/math/matrix_bit_code.cc
浏览文件 @
a25c3aeb
...
...
@@ -50,7 +50,7 @@ namespace math {
for j < codeLength:
op(a(i, j), b(0, index(i, j)))
*/
template
<
class
CodeTable
,
class
Op
,
typename
T
,
typename
Place
>
template
<
class
CodeTable
,
class
Op
,
typename
T
>
static
void
AddByBitCodeT
(
Op
op
,
CodeTable
code_table
,
const
framework
::
Tensor
&
codes
,
framework
::
Tensor
&
a
,
framework
::
Tensor
&
b
)
{
...
...
@@ -72,11 +72,11 @@ static void AddByBitCodeT(Op op, CodeTable code_table,
/* For j < codeLength:
a(i, j) += b(0, index(i, j))
*/
template
<
typename
T
,
typename
Place
>
template
<
typename
T
>
void
AddByBitCode
(
size_t
num_classes
,
const
framework
::
Tensor
&
codes
,
framework
::
Tensor
&
a
,
const
framework
::
Tensor
&
b
)
{
auto
op
=
[](
T
&
t
,
T
&
v
)
{
t
+=
v
;
};
AddByBitCodeT
<
T
,
Place
>
(
op
,
SimpleCodeTable
(
num_classes
),
codes
,
a
,
b
);
AddByBitCodeT
<
T
>
(
op
,
SimpleCodeTable
(
num_classes
),
codes
,
a
,
b
);
}
}
// namespace math
...
...
paddle/operators/math/matrix_bit_code.h
浏览文件 @
a25c3aeb
...
...
@@ -59,6 +59,10 @@ struct SimpleCodeTable {
int
max_code_length_
;
};
template
<
typename
T
>
void
AddByBitCode
(
size_t
num_classes
,
const
framework
::
Tensor
&
codes
,
framework
::
Tensor
&
a
,
const
framework
::
Tensor
&
b
);
}
// namespace math
}
// namespace operators
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录