Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
ERNIE
提交
4d0c99f7
E
ERNIE
项目概览
PaddlePaddle
/
ERNIE
大约 1 年 前同步成功
通知
109
Star
5997
Fork
1270
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
29
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
ERNIE
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
29
Issue
29
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4d0c99f7
编写于
11月 04, 2019
作者:
C
chenxuyi
提交者:
Meiyim
1月 16, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix python2 compat
上级
7677bced
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
8 addition
and
6 deletion
+8
-6
ernie/model/ernie.py
ernie/model/ernie.py
+5
-4
ernie/model/ernie_v1.py
ernie/model/ernie_v1.py
+3
-2
未找到文件。
ernie/model/ernie.py
浏览文件 @
4d0c99f7
...
@@ -24,6 +24,7 @@ import six
...
@@ -24,6 +24,7 @@ import six
import
logging
import
logging
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
io
import
open
from
io
import
open
from
paddle.fluid.layers
import
core
from
model.transformer_encoder
import
encoder
,
pre_process_layer
from
model.transformer_encoder
import
encoder
,
pre_process_layer
...
@@ -85,8 +86,8 @@ class ErnieModel(object):
...
@@ -85,8 +86,8 @@ class ErnieModel(object):
self
.
_pos_emb_name
=
"pos_embedding"
self
.
_pos_emb_name
=
"pos_embedding"
self
.
_sent_emb_name
=
"sent_embedding"
self
.
_sent_emb_name
=
"sent_embedding"
self
.
_task_emb_name
=
"task_embedding"
self
.
_task_emb_name
=
"task_embedding"
self
.
_dtype
=
"float16"
if
use_fp16
else
"float32"
self
.
_dtype
=
core
.
VarDesc
.
VarType
.
FP16
if
use_fp16
else
core
.
VarDesc
.
VarType
.
FP32
self
.
_emb_dtype
=
'float32'
self
.
_emb_dtype
=
core
.
VarDesc
.
VarType
.
FP32
# Initialize all weigths by truncated normal initializer, and all biases
# Initialize all weigths by truncated normal initializer, and all biases
# will be initialized by constant zero by default.
# will be initialized by constant zero by default.
...
@@ -138,7 +139,7 @@ class ErnieModel(object):
...
@@ -138,7 +139,7 @@ class ErnieModel(object):
emb_out
=
pre_process_layer
(
emb_out
=
pre_process_layer
(
emb_out
,
'nd'
,
self
.
_prepostprocess_dropout
,
name
=
'pre_encoder'
)
emb_out
,
'nd'
,
self
.
_prepostprocess_dropout
,
name
=
'pre_encoder'
)
if
self
.
_dtype
==
'float16'
:
if
self
.
_dtype
==
core
.
VarDesc
.
VarType
.
FP16
:
emb_out
=
fluid
.
layers
.
cast
(
x
=
emb_out
,
dtype
=
self
.
_dtype
)
emb_out
=
fluid
.
layers
.
cast
(
x
=
emb_out
,
dtype
=
self
.
_dtype
)
input_mask
=
fluid
.
layers
.
cast
(
x
=
input_mask
,
dtype
=
self
.
_dtype
)
input_mask
=
fluid
.
layers
.
cast
(
x
=
input_mask
,
dtype
=
self
.
_dtype
)
self_attn_mask
=
fluid
.
layers
.
matmul
(
self_attn_mask
=
fluid
.
layers
.
matmul
(
...
@@ -167,7 +168,7 @@ class ErnieModel(object):
...
@@ -167,7 +168,7 @@ class ErnieModel(object):
postprocess_cmd
=
"dan"
,
postprocess_cmd
=
"dan"
,
param_initializer
=
self
.
_param_initializer
,
param_initializer
=
self
.
_param_initializer
,
name
=
'encoder'
)
name
=
'encoder'
)
if
self
.
_dtype
==
'float16'
:
if
self
.
_dtype
==
core
.
VarDesc
.
VarType
.
FP16
:
self
.
_enc_out
=
fluid
.
layers
.
cast
(
self
.
_enc_out
=
fluid
.
layers
.
cast
(
x
=
self
.
_enc_out
,
dtype
=
self
.
_emb_dtype
)
x
=
self
.
_enc_out
,
dtype
=
self
.
_emb_dtype
)
...
...
ernie/model/ernie_v1.py
浏览文件 @
4d0c99f7
...
@@ -24,6 +24,7 @@ import logging
...
@@ -24,6 +24,7 @@ import logging
import
six
import
six
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
io
import
open
from
io
import
open
from
paddle.fluid.layers
import
core
from
model.transformer_encoder
import
encoder
,
pre_process_layer
from
model.transformer_encoder
import
encoder
,
pre_process_layer
...
@@ -76,7 +77,7 @@ class ErnieModel(object):
...
@@ -76,7 +77,7 @@ class ErnieModel(object):
self
.
_word_emb_name
=
"word_embedding"
self
.
_word_emb_name
=
"word_embedding"
self
.
_pos_emb_name
=
"pos_embedding"
self
.
_pos_emb_name
=
"pos_embedding"
self
.
_sent_emb_name
=
"sent_embedding"
self
.
_sent_emb_name
=
"sent_embedding"
self
.
_dtype
=
'float16'
if
use_fp16
else
'float32'
self
.
_dtype
=
core
.
VarDesc
.
VarType
.
FP16
if
use_fp16
else
core
.
VarDesc
.
VarType
.
FP32
# Initialize all weigths by truncated normal initializer, and all biases
# Initialize all weigths by truncated normal initializer, and all biases
# will be initialized by constant zero by default.
# will be initialized by constant zero by default.
...
@@ -114,7 +115,7 @@ class ErnieModel(object):
...
@@ -114,7 +115,7 @@ class ErnieModel(object):
emb_out
=
pre_process_layer
(
emb_out
=
pre_process_layer
(
emb_out
,
'nd'
,
self
.
_prepostprocess_dropout
,
name
=
'pre_encoder'
)
emb_out
,
'nd'
,
self
.
_prepostprocess_dropout
,
name
=
'pre_encoder'
)
if
self
.
_dtype
==
'float16'
:
if
self
.
_dtype
==
core
.
VarDesc
.
VarType
.
FP16
:
input_mask
=
fluid
.
layers
.
cast
(
x
=
input_mask
,
dtype
=
self
.
_dtype
)
input_mask
=
fluid
.
layers
.
cast
(
x
=
input_mask
,
dtype
=
self
.
_dtype
)
self_attn_mask
=
fluid
.
layers
.
matmul
(
self_attn_mask
=
fluid
.
layers
.
matmul
(
x
=
input_mask
,
y
=
input_mask
,
transpose_y
=
True
)
x
=
input_mask
,
y
=
input_mask
,
transpose_y
=
True
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录