Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
0fe84bc3
M
models
项目概览
PaddlePaddle
/
models
大约 2 年 前同步成功
通知
232
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看板
提交
0fe84bc3
编写于
10月 16, 2018
作者:
M
mapingshuo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add infersent and sse model
上级
ec23790d
变更
11
展开全部
显示空白变更内容
内联
并排
Showing
11 changed file
with
2058 addition
and
4 deletion
+2058
-4
fluid/text_matching_on_quora/cdssm_base.log
fluid/text_matching_on_quora/cdssm_base.log
+1834
-0
fluid/text_matching_on_quora/configs/__init__.py
fluid/text_matching_on_quora/configs/__init__.py
+3
-0
fluid/text_matching_on_quora/configs/cdssm.py
fluid/text_matching_on_quora/configs/cdssm.py
+1
-1
fluid/text_matching_on_quora/configs/dec_att.py
fluid/text_matching_on_quora/configs/dec_att.py
+28
-2
fluid/text_matching_on_quora/configs/infer_sent.py
fluid/text_matching_on_quora/configs/infer_sent.py
+48
-0
fluid/text_matching_on_quora/configs/sse.py
fluid/text_matching_on_quora/configs/sse.py
+29
-0
fluid/text_matching_on_quora/models/__init__.py
fluid/text_matching_on_quora/models/__init__.py
+2
-1
fluid/text_matching_on_quora/models/infer_sent.py
fluid/text_matching_on_quora/models/infer_sent.py
+58
-0
fluid/text_matching_on_quora/models/match_layers.py
fluid/text_matching_on_quora/models/match_layers.py
+0
-0
fluid/text_matching_on_quora/models/my_layers.py
fluid/text_matching_on_quora/models/my_layers.py
+0
-0
fluid/text_matching_on_quora/models/sse.py
fluid/text_matching_on_quora/models/sse.py
+55
-0
未找到文件。
fluid/text_matching_on_quora/cdssm_base.log
0 → 100644
浏览文件 @
0fe84bc3
此差异已折叠。
点击以展开。
fluid/text_matching_on_quora/configs/__init__.py
浏览文件 @
0fe84bc3
from
cdssm
import
cdssm_base
from
cdssm
import
cdssm_base
from
dec_att
import
decatt_glove
from
dec_att
import
decatt_glove
from
sse
import
sse_base
from
infer_sent
import
infer_sent_v1
from
infer_sent
import
infer_sent_v2
fluid/text_matching_on_quora/configs/cdssm.py
浏览文件 @
0fe84bc3
...
@@ -7,7 +7,7 @@ def cdssm_base():
...
@@ -7,7 +7,7 @@ def cdssm_base():
"""
"""
config
=
basic_config
.
config
()
config
=
basic_config
.
config
()
config
.
learning_rate
=
0.001
config
.
learning_rate
=
0.001
config
.
save_dirname
=
"
cdssm_model
"
config
.
save_dirname
=
"
model_dir
"
config
.
use_pretrained_word_embedding
=
True
config
.
use_pretrained_word_embedding
=
True
config
.
dict_dim
=
40000
# approx_vocab_size
config
.
dict_dim
=
40000
# approx_vocab_size
...
...
fluid/text_matching_on_quora/configs/dec_att.py
浏览文件 @
0fe84bc3
...
@@ -7,7 +7,7 @@ def decatt_glove():
...
@@ -7,7 +7,7 @@ def decatt_glove():
"""
"""
config
=
basic_config
.
config
()
config
=
basic_config
.
config
()
config
.
learning_rate
=
0.05
config
.
learning_rate
=
0.05
config
.
save_dirname
=
"
decatt_model
"
config
.
save_dirname
=
"
model_dir
"
config
.
use_pretrained_word_embedding
=
True
config
.
use_pretrained_word_embedding
=
True
config
.
dict_dim
=
40000
# approx_vocab_size
config
.
dict_dim
=
40000
# approx_vocab_size
config
.
metric_type
=
[
'accuracy'
,
'accuracy_with_threshold'
]
config
.
metric_type
=
[
'accuracy'
,
'accuracy_with_threshold'
]
...
@@ -29,4 +29,30 @@ def decatt_glove():
...
@@ -29,4 +29,30 @@ def decatt_glove():
return
config
return
config
def
decatt_word
():
"""
use config 'decAtt_glove' in the paper 'Neural Paraphrase Identification of Questions with Noisy Pretraining'
"""
config
=
basic_config
.
config
()
config
.
learning_rate
=
0.05
config
.
save_dirname
=
"model_dir"
config
.
use_pretrained_word_embedding
=
False
config
.
dict_dim
=
40000
# approx_vocab_size
config
.
metric_type
=
[
'accuracy'
,
'accuracy_with_threshold'
]
config
.
optimizer_type
=
'sgd'
config
.
lr_decay
=
1
config
.
use_lod_tensor
=
False
config
.
embedding_norm
=
False
config
.
OOV_fill
=
'uniform'
config
.
duplicate_data
=
False
# net config
config
.
emb_dim
=
300
config
.
proj_emb_dim
=
200
#TODO: has project?
config
.
num_units
=
[
400
,
200
]
config
.
word_embedding_trainable
=
True
config
.
droprate
=
0.1
config
.
share_wight_btw_seq
=
True
config
.
class_dim
=
2
return
config
fluid/text_matching_on_quora/configs/infer_sent.py
0 → 100755
浏览文件 @
0fe84bc3
import
basic_config
def
infer_sent_v1
():
"""
set configs
"""
config
=
basic_config
.
config
()
config
.
learning_rate
=
0.1
config
.
lr_decay
=
0.99
config
.
optimizer_type
=
'sgd'
config
.
save_dirname
=
"model_dir"
config
.
use_pretrained_word_embedding
=
False
config
.
dict_dim
=
40000
# approx_vocab_size
config
.
class_dim
=
2
# net config
config
.
emb_dim
=
300
config
.
droprate_lstm
=
0.0
config
.
droprate_fc
=
0.0
config
.
word_embedding_trainable
=
False
config
.
rnn_hid_dim
=
2048
config
.
mlp_non_linear
=
False
return
config
def
infer_sent_v2
():
"""
use our own config
"""
config
=
basic_config
.
config
()
config
.
learning_rate
=
0.0002
config
.
lr_decay
=
0.99
config
.
optimizer_type
=
'adam'
config
.
save_dirname
=
"model_dir"
config
.
use_pretrained_word_embedding
=
True
config
.
dict_dim
=
40000
# approx_vocab_size
config
.
class_dim
=
2
# net config
config
.
emb_dim
=
300
config
.
droprate_lstm
=
0.0
config
.
droprate_fc
=
0.2
config
.
word_embedding_trainable
=
False
config
.
rnn_hid_dim
=
2048
config
.
mlp_non_linear
=
True
return
config
fluid/text_matching_on_quora/configs/sse.py
0 → 100755
浏览文件 @
0fe84bc3
import
basic_config
def
sse_base
():
"""
use config in the paper 'Shortcut-Stacked Sentence Encoders for Multi-Domain Inference'
"""
config
=
basic_config
.
config
()
config
.
learning_rate
=
0.0002
config
.
lr_decay
=
0.7
config
.
save_dirname
=
"model_dir"
config
.
use_pretrained_word_embedding
=
True
config
.
dict_dim
=
40000
# approx_vocab_size
config
.
metric_type
=
[
'accuracy'
]
config
.
optimizer_type
=
'adam'
config
.
use_lod_tensor
=
True
config
.
embedding_norm
=
False
config
.
OOV_fill
=
'uniform'
config
.
duplicate_data
=
False
# net config
config
.
emb_dim
=
300
config
.
rnn_hid_dim
=
[
512
,
1024
,
2048
]
config
.
fc_dim
=
[
1600
,
1600
]
config
.
droprate_lstm
=
0.0
config
.
droprate_fc
=
0.1
config
.
class_dim
=
2
return
config
fluid/text_matching_on_quora/models/__init__.py
浏览文件 @
0fe84bc3
from
cdssm
import
cdssmNet
from
cdssm
import
cdssmNet
from
dec_att
import
DecAttNet
from
dec_att
import
DecAttNet
from
sse
import
SSENet
from
infer_sent
import
InferSentNet
fluid/text_matching_on_quora/models/infer_sent.py
0 → 100644
浏览文件 @
0fe84bc3
import
paddle.fluid
as
fluid
from
my_layers
import
bi_lstm_layer
from
match_layers
import
ElementwiseMatching
class
InferSentNet
():
"""
Base on the paper: Supervised Learning of Universal Sentence Representations from Natural Language Inference Data:
https://arxiv.org/abs/1705.02364
"""
def
__init__
(
self
,
config
):
self
.
_config
=
config
def
__call__
(
self
,
seq1
,
seq2
,
label
):
return
self
.
body
(
seq1
,
seq2
,
label
,
self
.
_config
)
def
body
(
self
,
seq1
,
seq2
,
label
,
config
):
"""Body function"""
seq1_rnn
=
self
.
encoder
(
seq1
)
seq2_rnn
=
self
.
encoder
(
seq2
)
seq_match
=
ElementwiseMatching
(
seq1_rnn
,
seq2_rnn
)
mlp_res
=
self
.
MLP
(
seq_match
)
prediction
=
fluid
.
layers
.
fc
(
mlp_res
,
size
=
self
.
_config
.
class_dim
,
act
=
'softmax'
)
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
loss
)
acc
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
return
avg_cost
,
acc
,
prediction
def
encoder
(
self
,
seq
):
"""encoder"""
embed
=
fluid
.
layers
.
embedding
(
input
=
seq
,
size
=
[
self
.
_config
.
dict_dim
,
self
.
_config
.
emb_dim
],
param_attr
=
fluid
.
ParamAttr
(
name
=
'emb.w'
,
trainable
=
self
.
_config
.
word_embedding_trainable
))
bi_lstm_h
=
bi_lstm_layer
(
embed
,
rnn_hid_dim
=
self
.
_config
.
rnn_hid_dim
,
name
=
'encoder'
)
bi_lstm_h
=
fluid
.
layers
.
dropout
(
bi_lstm_h
,
dropout_prob
=
self
.
_config
.
droprate_lstm
)
pool
=
fluid
.
layers
.
sequence_pool
(
input
=
bi_lstm_h
,
pool_type
=
'max'
)
return
pool
def
MLP
(
self
,
vec
):
if
self
.
_config
.
mlp_non_linear
:
drop1
=
fluid
.
layers
.
dropout
(
vec
,
dropout_prob
=
self
.
_config
.
droprate_fc
)
fc1
=
fluid
.
layers
.
fc
(
drop1
,
size
=
512
,
act
=
'tanh'
)
drop2
=
fluid
.
layers
.
dropout
(
fc1
,
dropout_prob
=
self
.
_config
.
droprate_fc
)
fc2
=
fluid
.
layers
.
fc
(
drop2
,
size
=
512
,
act
=
'tanh'
)
res
=
fluid
.
layers
.
dropout
(
fc2
,
dropout_prob
=
self
.
_config
.
droprate_fc
)
else
:
fc1
=
fluid
.
layers
.
fc
(
vec
,
size
=
512
,
act
=
None
)
res
=
fluid
.
layers
.
fc
(
fc1
,
size
=
512
,
act
=
None
)
return
res
fluid/text_matching_on_quora/match_layers.py
→
fluid/text_matching_on_quora/m
odels/m
atch_layers.py
浏览文件 @
0fe84bc3
文件已移动
fluid/text_matching_on_quora/my_layers.py
→
fluid/text_matching_on_quora/m
odels/m
y_layers.py
浏览文件 @
0fe84bc3
文件已移动
fluid/text_matching_on_quora/models/sse.py
0 → 100644
浏览文件 @
0fe84bc3
import
paddle.fluid
as
fluid
from
my_layers
import
bi_lstm_layer
from
match_layers
import
ElementwiseMatching
class
SSENet
():
"""
SSE net: Shortcut-Stacked Sentence Encoders for Multi-Domain Inference
https://arxiv.org/abs/1708.02312
"""
def
__init__
(
self
,
config
):
self
.
_config
=
config
def
__call__
(
self
,
seq1
,
seq2
,
label
):
return
self
.
body
(
seq1
,
seq2
,
label
,
self
.
_config
)
def
body
(
self
,
seq1
,
seq2
,
label
,
config
):
"""Body function"""
def
stacked_bi_rnn_model
(
seq
):
embed
=
fluid
.
layers
.
embedding
(
input
=
seq
,
size
=
[
self
.
_config
.
dict_dim
,
self
.
_config
.
emb_dim
],
param_attr
=
'emb.w'
)
stacked_lstm_out
=
[
embed
]
for
i
in
range
(
len
(
self
.
_config
.
rnn_hid_dim
)):
if
i
==
0
:
feature
=
embed
else
:
feature
=
fluid
.
layers
.
concat
(
input
=
stacked_lstm_out
,
axis
=
1
)
bi_lstm_h
=
bi_lstm_layer
(
feature
,
rnn_hid_dim
=
self
.
_config
.
rnn_hid_dim
[
i
],
name
=
"lstm_"
+
str
(
i
))
# add dropout except for the last stacked lstm layer
if
i
!=
len
(
self
.
_config
.
rnn_hid_dim
)
-
1
:
bi_lstm_h
=
fluid
.
layers
.
dropout
(
bi_lstm_h
,
dropout_prob
=
self
.
_config
.
droprate_lstm
)
stacked_lstm_out
.
append
(
bi_lstm_h
)
pool
=
fluid
.
layers
.
sequence_pool
(
input
=
bi_lstm_h
,
pool_type
=
'max'
)
return
pool
def
MLP
(
vec
):
for
i
in
range
(
len
(
self
.
_config
.
fc_dim
)):
vec
=
fluid
.
layers
.
fc
(
vec
,
size
=
self
.
_config
.
fc_dim
[
i
],
act
=
'relu'
)
# add dropout after every layer of MLP
vec
=
fluid
.
layers
.
dropout
(
vec
,
dropout_prob
=
self
.
_config
.
droprate_fc
)
return
vec
seq1_rnn
=
stacked_bi_rnn_model
(
seq1
)
seq2_rnn
=
stacked_bi_rnn_model
(
seq2
)
seq_match
=
ElementwiseMatching
(
seq1_rnn
,
seq2_rnn
)
mlp_res
=
MLP
(
seq_match
)
prediction
=
fluid
.
layers
.
fc
(
mlp_res
,
size
=
self
.
_config
.
class_dim
,
act
=
'softmax'
)
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
loss
)
acc
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
return
avg_cost
,
acc
,
prediction
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录