Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
56e2729c
H
hapi
项目概览
PaddlePaddle
/
hapi
通知
11
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hapi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
56e2729c
编写于
5月 13, 2020
作者:
G
guosheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove hapi.text apis' reuse parameter args for coverage.
test=develop
上级
6e962618
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
148 addition
and
803 deletion
+148
-803
examples/sentiment_classification/models.py
examples/sentiment_classification/models.py
+3
-2
hapi/tests/test_text.py
hapi/tests/test_text.py
+0
-41
hapi/text/__init__.py
hapi/text/__init__.py
+0
-3
hapi/text/text.py
hapi/text/text.py
+145
-757
未找到文件。
examples/sentiment_classification/models.py
浏览文件 @
56e2729c
...
...
@@ -16,8 +16,9 @@ from paddle.fluid.dygraph.nn import Linear, Embedding
from
paddle.fluid.dygraph.base
import
to_variable
import
numpy
as
np
from
hapi.model
import
Model
from
hapi.text.text
import
GRUEncoder
as
BiGRUEncoder
from
hapi.text.test
import
BOWEncoder
,
CNNEncoder
,
GRUEncoder
from
hapi.text.text
import
_GRUEncoder
as
GRUEncoder
from
hapi.text.text
import
_GRUEncoder
as
BiGRUEncoder
from
hapi.text.test
import
BOWEncoder
,
CNNEncoder
class
CNN
(
Model
):
...
...
hapi/tests/test_text.py
浏览文件 @
56e2729c
...
...
@@ -28,47 +28,6 @@ from hapi.model import Model, Input, set_device
from
hapi.text.text
import
*
def
sigmoid
(
x
):
return
1.
/
(
1.
+
np
.
exp
(
-
x
))
def
tanh
(
x
):
return
2.
*
sigmoid
(
2.
*
x
)
-
1.
def
lstm_step
(
step_in
,
pre_hidden
,
pre_cell
,
gate_w
,
gate_b
,
forget_bias
=
1.0
):
concat_1
=
np
.
concatenate
([
step_in
,
pre_hidden
],
1
)
gate_input
=
np
.
matmul
(
concat_1
,
gate_w
)
gate_input
+=
gate_b
i
,
j
,
f
,
o
=
np
.
split
(
gate_input
,
indices_or_sections
=
4
,
axis
=
1
)
new_cell
=
pre_cell
*
sigmoid
(
f
+
forget_bias
)
+
sigmoid
(
i
)
*
tanh
(
j
)
new_hidden
=
tanh
(
new_cell
)
*
sigmoid
(
o
)
return
new_hidden
,
new_cell
def
gru_step
(
step_in
,
pre_hidden
,
gate_w
,
gate_b
,
candidate_w
,
candidate_b
):
concat_1
=
np
.
concatenate
([
step_in
,
pre_hidden
],
1
)
gate_input
=
np
.
matmul
(
concat_1
,
gate_w
)
gate_input
+=
gate_b
gate_input
=
sigmoid
(
gate_input
)
r
,
u
=
np
.
split
(
gate_input
,
indices_or_sections
=
2
,
axis
=
1
)
r_hidden
=
r
*
pre_hidden
candidate
=
np
.
matmul
(
np
.
concatenate
([
step_in
,
r_hidden
],
1
),
candidate_w
)
candidate
+=
candidate_b
c
=
tanh
(
candidate
)
new_hidden
=
u
*
pre_hidden
+
(
1
-
u
)
*
c
return
new_hidden
class
ModuleApiTest
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
):
...
...
hapi/text/__init__.py
浏览文件 @
56e2729c
...
...
@@ -37,9 +37,6 @@ from hapi.text.text import TransformerDecoder as TransformerDecoder
from
hapi.text.text
import
TransformerCell
as
TransformerCell
from
hapi.text.text
import
TransformerBeamSearchDecoder
as
TransformerBeamSearchDecoder
from
hapi.text.text
import
GRUCell
as
GRUCell
from
hapi.text.text
import
GRUEncoderCell
as
GRUEncoderCell
from
hapi.text.text
import
BiGRU
as
BiGRU
from
hapi.text.text
import
LinearChainCRF
as
LinearChainCRF
from
hapi.text.text
import
CRFDecoding
as
CRFDecoding
from
hapi.text.text
import
SequenceTagging
as
SequenceTagging
hapi/text/text.py
浏览文件 @
56e2729c
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录