Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
6d637a93
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6d637a93
编写于
5月 16, 2019
作者:
L
lilu
提交者:
GitHub
5月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test=develop (#2249)
上级
0a31618b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
17 deletion
+18
-17
PaddleNLP/models/dialogue_model_toolkit/auto_dialogue_evaluation/net.py
...ls/dialogue_model_toolkit/auto_dialogue_evaluation/net.py
+18
-17
未找到文件。
PaddleNLP/models/dialogue_model_toolkit/auto_dialogue_evaluation/net.py
浏览文件 @
6d637a93
...
@@ -11,22 +11,24 @@ import math
...
@@ -11,22 +11,24 @@ import math
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
paddle
import
paddle
class
Network
(
object
):
class
Network
(
object
):
"""
"""
Network
Network
"""
"""
def
__init__
(
self
,
vocab_size
,
def
__init__
(
self
,
emb_size
,
vocab_size
,
hidden_size
,
emb_size
,
clip_value
=
10.0
,
hidden_size
,
word_emb_name
=
"shared_word_emb"
,
clip_value
=
10.0
,
lstm_W_name
=
"shared_lstm_W"
,
word_emb_name
=
"shared_word_emb"
,
lstm_bias_name
=
"shared_lstm_bias"
):
lstm_W_name
=
"shared_lstm_W"
,
lstm_bias_name
=
"shared_lstm_bias"
):
"""
"""
Init function
Init function
"""
"""
self
.
vocab_size
=
vocab_size
self
.
vocab_size
=
vocab_size
self
.
emb_size
=
emb_size
self
.
emb_size
=
emb_size
self
.
hidden_size
=
hidden_size
self
.
hidden_size
=
hidden_size
...
@@ -44,8 +46,7 @@ class Network(object):
...
@@ -44,8 +46,7 @@ class Network(object):
name
=
"context_wordseq"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
name
=
"context_wordseq"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
response_wordseq
=
fluid
.
layers
.
data
(
response_wordseq
=
fluid
.
layers
.
data
(
name
=
"response_wordseq"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
name
=
"response_wordseq"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
layers
.
data
(
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"float32"
)
name
=
"label"
,
shape
=
[
1
],
dtype
=
"float32"
)
self
.
_feed_name
=
[
"context_wordseq"
,
"response_wordseq"
,
"label"
]
self
.
_feed_name
=
[
"context_wordseq"
,
"response_wordseq"
,
"label"
]
self
.
_feed_infer_name
=
[
"context_wordseq"
,
"response_wordseq"
]
self
.
_feed_infer_name
=
[
"context_wordseq"
,
"response_wordseq"
]
...
@@ -58,7 +59,7 @@ class Network(object):
...
@@ -58,7 +59,7 @@ class Network(object):
param_attr
=
fluid
.
ParamAttr
(
param_attr
=
fluid
.
ParamAttr
(
name
=
self
.
word_emb_name
,
name
=
self
.
word_emb_name
,
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
0.1
)))
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
0.1
)))
response_emb
=
fluid
.
layers
.
embedding
(
response_emb
=
fluid
.
layers
.
embedding
(
input
=
response_wordseq
,
input
=
response_wordseq
,
size
=
[
self
.
vocab_size
,
self
.
emb_size
],
size
=
[
self
.
vocab_size
,
self
.
emb_size
],
...
@@ -66,7 +67,7 @@ class Network(object):
...
@@ -66,7 +67,7 @@ class Network(object):
param_attr
=
fluid
.
ParamAttr
(
param_attr
=
fluid
.
ParamAttr
(
name
=
self
.
word_emb_name
,
name
=
self
.
word_emb_name
,
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
0.1
)))
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
0.1
)))
#fc to fit dynamic LSTM
#fc to fit dynamic LSTM
context_fc
=
fluid
.
layers
.
fc
(
context_fc
=
fluid
.
layers
.
fc
(
input
=
context_emb
,
input
=
context_emb
,
...
@@ -96,10 +97,10 @@ class Network(object):
...
@@ -96,10 +97,10 @@ class Network(object):
bias_attr
=
fluid
.
ParamAttr
(
name
=
self
.
lstm_bias_name
))
bias_attr
=
fluid
.
ParamAttr
(
name
=
self
.
lstm_bias_name
))
response_rep
=
fluid
.
layers
.
sequence_last_step
(
input
=
response_rep
)
response_rep
=
fluid
.
layers
.
sequence_last_step
(
input
=
response_rep
)
print
(
'response_rep shape: %s'
%
str
(
response_rep
.
shape
))
print
(
'response_rep shape: %s'
%
str
(
response_rep
.
shape
))
logits
=
fluid
.
layers
.
bilinear_tensor_product
(
logits
=
fluid
.
layers
.
bilinear_tensor_product
(
context_rep
,
response_rep
,
size
=
1
)
context_rep
,
response_rep
,
size
=
1
)
print
(
'logits shape: %s'
%
str
(
logits
.
shape
))
#[batch,1]
print
(
'logits shape: %s'
%
str
(
logits
.
shape
))
#[batch,1]
if
loss_type
==
'CLS'
:
if
loss_type
==
'CLS'
:
loss
=
fluid
.
layers
.
sigmoid_cross_entropy_with_logits
(
logits
,
label
)
loss
=
fluid
.
layers
.
sigmoid_cross_entropy_with_logits
(
logits
,
label
)
...
@@ -111,6 +112,7 @@ class Network(object):
...
@@ -111,6 +112,7 @@ class Network(object):
elif
loss_type
==
'L2'
:
elif
loss_type
==
'L2'
:
norm_score
=
2
*
fluid
.
layers
.
sigmoid
(
logits
)
norm_score
=
2
*
fluid
.
layers
.
sigmoid
(
logits
)
loss
=
fluid
.
layers
.
square_error_cost
(
norm_score
,
label
)
/
4
loss
=
fluid
.
layers
.
square_error_cost
(
norm_score
,
label
)
/
4
loss
=
fluid
.
layers
.
reduce_mean
(
loss
)
else
:
else
:
raise
ValueError
raise
ValueError
...
@@ -129,10 +131,9 @@ class Network(object):
...
@@ -129,10 +131,9 @@ class Network(object):
Return feed names
Return feed names
"""
"""
return
self
.
_feed_name
return
self
.
_feed_name
def
get_feed_inference_names
(
self
):
def
get_feed_inference_names
(
self
):
"""
"""
Return inference names
Return inference names
"""
"""
return
self
.
_feed_infer_name
return
self
.
_feed_infer_name
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录