Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
c4d61454
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看板
未验证
提交
c4d61454
编写于
9月 06, 2018
作者:
Z
Zeng Jinle
提交者:
GitHub
9月 06, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1230 from kuke/update_eval
Upload eval for douban data
上级
4aa817ec
17b3f6cb
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
114 addition
and
8 deletion
+114
-8
fluid/deep_attention_matching_net/douban/test.sh
fluid/deep_attention_matching_net/douban/test.sh
+3
-2
fluid/deep_attention_matching_net/douban/train.sh
fluid/deep_attention_matching_net/douban/train.sh
+2
-0
fluid/deep_attention_matching_net/model.py
fluid/deep_attention_matching_net/model.py
+1
-1
fluid/deep_attention_matching_net/test_and_evaluate.py
fluid/deep_attention_matching_net/test_and_evaluate.py
+9
-1
fluid/deep_attention_matching_net/train_and_evaluate.py
fluid/deep_attention_matching_net/train_and_evaluate.py
+13
-4
fluid/deep_attention_matching_net/ubuntu/train.sh
fluid/deep_attention_matching_net/ubuntu/train.sh
+1
-0
fluid/deep_attention_matching_net/utils/douban_evaluation.py
fluid/deep_attention_matching_net/utils/douban_evaluation.py
+85
-0
未找到文件。
fluid/deep_attention_matching_net/douban/test.sh
浏览文件 @
c4d61454
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3
python
-u
test_and_evaluate.py
--use_cuda
\
python
-u
../test_and_evaluate.py
--use_cuda
\
--ext_eval
\
--data_path
./data/data.pkl
\
--save_path
./
\
--save_path
./
eval_10000
\
--model_path
models/step_10000
\
--batch_size
100
\
--vocab_size
172130
\
...
...
fluid/deep_attention_matching_net/douban/train.sh
浏览文件 @
c4d61454
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3
python
-u
../train_and_evaluate.py
--use_cuda
\
--data_path
./data/data.pkl
\
--ext_eval
\
--word_emb_init
./data/word_embedding.pkl
\
--save_path
./models
\
--batch_size
100
\
--vocab_size
172130
\
...
...
fluid/deep_attention_matching_net/model.py
浏览文件 @
c4d61454
...
...
@@ -131,6 +131,6 @@ class Net(object):
sim
=
fluid
.
layers
.
concat
(
input
=
sim_turns
,
axis
=
2
)
# for douban
final_info
=
layers
.
cnn_3d
(
sim
,
16
,
16
)
final_info
=
layers
.
cnn_3d
(
sim
,
32
,
16
)
loss
,
logits
=
layers
.
loss
(
final_info
,
label
)
return
loss
,
logits
fluid/deep_attention_matching_net/test_and_evaluate.py
浏览文件 @
c4d61454
...
...
@@ -8,7 +8,6 @@ import paddle.fluid as fluid
import
utils.reader
as
reader
import
cPickle
as
pickle
from
utils.util
import
print_arguments
import
utils.evaluation
as
eva
from
model
import
Net
...
...
@@ -50,6 +49,10 @@ def parse_args():
'--use_cuda'
,
action
=
'store_true'
,
help
=
'If set, use cuda for training.'
)
parser
.
add_argument
(
'--ext_eval'
,
action
=
'store_true'
,
help
=
'If set, use MAP, MRR ect for evaluation.'
)
parser
.
add_argument
(
'--max_turn_num'
,
type
=
int
,
...
...
@@ -147,6 +150,11 @@ def test(args):
train_data
,
val_data
,
test_data
=
pickle
.
load
(
open
(
args
.
data_path
,
'rb'
))
print
(
"finish loading data ..."
)
if
args
.
ext_eval
:
import
utils.douban_evaluation
as
eva
else
:
import
utils.evaluation
as
eva
test_batches
=
reader
.
build_batches
(
test_data
,
data_conf
)
test_batch_num
=
len
(
test_batches
[
"response"
])
...
...
fluid/deep_attention_matching_net/train_and_evaluate.py
浏览文件 @
c4d61454
...
...
@@ -8,7 +8,6 @@ import paddle.fluid as fluid
import
utils.reader
as
reader
import
cPickle
as
pickle
from
utils.util
import
print_arguments
import
utils.evaluation
as
eva
from
model
import
Net
...
...
@@ -34,7 +33,7 @@ def parse_args():
parser
.
add_argument
(
'--data_path'
,
type
=
str
,
default
=
"data/
ubuntu/
data_small.pkl"
,
default
=
"data/data_small.pkl"
,
help
=
'Path to training data. (default: %(default)s)'
)
parser
.
add_argument
(
'--save_path'
,
...
...
@@ -45,6 +44,10 @@ def parse_args():
'--use_cuda'
,
action
=
'store_true'
,
help
=
'If set, use cuda for training.'
)
parser
.
add_argument
(
'--ext_eval'
,
action
=
'store_true'
,
help
=
'If set, use MAP, MRR ect for evaluation.'
)
parser
.
add_argument
(
'--max_turn_num'
,
type
=
int
,
...
...
@@ -74,7 +77,7 @@ def parse_args():
'--_EOS_'
,
type
=
int
,
default
=
28270
,
help
=
'The id for end of sentence in vocabulary.'
)
help
=
'The id for
the
end of sentence in vocabulary.'
)
parser
.
add_argument
(
'--stack_num'
,
type
=
int
,
...
...
@@ -140,9 +143,15 @@ def train(args):
main_program
=
test_program
,
share_vars_from
=
train_exe
)
if
args
.
ext_eval
:
import
utils.douban_evaluation
as
eva
else
:
import
utils.evaluation
as
eva
if
args
.
word_emb_init
is
not
None
:
print
(
"start loading word embedding init ..."
)
word_emb
=
pickle
.
load
(
open
(
args
.
word_emb_init
,
'rb'
)).
astype
(
'float32'
)
word_emb
=
np
.
array
(
pickle
.
load
(
open
(
args
.
word_emb_init
,
'rb'
))).
astype
(
'float32'
)
print
(
"finish loading word embedding init ..."
)
print
(
"start loading data ..."
)
...
...
fluid/deep_attention_matching_net/ubuntu/train.sh
浏览文件 @
c4d61454
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3
python
-u
../train_and_evaluate.py
--use_cuda
\
--data_path
./data/data.pkl
\
--word_emb_init
./data/word_embedding.pkl
\
--save_path
./models
\
--batch_size
100
\
--vocab_size
434512
\
...
...
fluid/deep_attention_matching_net/utils/douban_evaluation.py
0 → 100644
浏览文件 @
c4d61454
import
sys
import
numpy
as
np
from
sklearn.metrics
import
average_precision_score
def
mean_average_precision
(
sort_data
):
#to do
count_1
=
0
sum_precision
=
0
for
index
in
range
(
len
(
sort_data
)):
if
sort_data
[
index
][
1
]
==
1
:
count_1
+=
1
sum_precision
+=
1.0
*
count_1
/
(
index
+
1
)
return
sum_precision
/
count_1
def
mean_reciprocal_rank
(
sort_data
):
sort_lable
=
[
s_d
[
1
]
for
s_d
in
sort_data
]
assert
1
in
sort_lable
return
1.0
/
(
1
+
sort_lable
.
index
(
1
))
def
precision_at_position_1
(
sort_data
):
if
sort_data
[
0
][
1
]
==
1
:
return
1
else
:
return
0
def
recall_at_position_k_in_10
(
sort_data
,
k
):
sort_lable
=
[
s_d
[
1
]
for
s_d
in
sort_data
]
select_lable
=
sort_lable
[:
k
]
return
1.0
*
select_lable
.
count
(
1
)
/
sort_lable
.
count
(
1
)
def
evaluation_one_session
(
data
):
sort_data
=
sorted
(
data
,
key
=
lambda
x
:
x
[
0
],
reverse
=
True
)
m_a_p
=
mean_average_precision
(
sort_data
)
m_r_r
=
mean_reciprocal_rank
(
sort_data
)
p_1
=
precision_at_position_1
(
sort_data
)
r_1
=
recall_at_position_k_in_10
(
sort_data
,
1
)
r_2
=
recall_at_position_k_in_10
(
sort_data
,
2
)
r_5
=
recall_at_position_k_in_10
(
sort_data
,
5
)
return
m_a_p
,
m_r_r
,
p_1
,
r_1
,
r_2
,
r_5
def
evaluate
(
file_path
):
sum_m_a_p
=
0
sum_m_r_r
=
0
sum_p_1
=
0
sum_r_1
=
0
sum_r_2
=
0
sum_r_5
=
0
i
=
0
total_num
=
0
with
open
(
file_path
,
'r'
)
as
infile
:
for
line
in
infile
:
if
i
%
10
==
0
:
data
=
[]
tokens
=
line
.
strip
().
split
(
'
\t
'
)
data
.
append
((
float
(
tokens
[
0
]),
int
(
tokens
[
1
])))
if
i
%
10
==
9
:
total_num
+=
1
m_a_p
,
m_r_r
,
p_1
,
r_1
,
r_2
,
r_5
=
evaluation_one_session
(
data
)
sum_m_a_p
+=
m_a_p
sum_m_r_r
+=
m_r_r
sum_p_1
+=
p_1
sum_r_1
+=
r_1
sum_r_2
+=
r_2
sum_r_5
+=
r_5
i
+=
1
#print('total num: %s' %total_num)
#print('MAP: %s' %(1.0*sum_m_a_p/total_num))
#print('MRR: %s' %(1.0*sum_m_r_r/total_num))
#print('P@1: %s' %(1.0*sum_p_1/total_num))
return
(
1.0
*
sum_m_a_p
/
total_num
,
1.0
*
sum_m_r_r
/
total_num
,
1.0
*
sum_p_1
/
total_num
,
1.0
*
sum_r_1
/
total_num
,
1.0
*
sum_r_2
/
total_num
,
1.0
*
sum_r_5
/
total_num
)
if
__name__
==
'__main__'
:
result
=
evaluate
(
sys
.
argv
[
1
])
for
r
in
result
:
print
(
r
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录