Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
eddf9bac
B
book
项目概览
PaddlePaddle
/
book
通知
17
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
40
列表
看板
标记
里程碑
合并请求
37
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
B
book
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
40
Issue
40
列表
看板
标记
里程碑
合并请求
37
合并请求
37
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
eddf9bac
编写于
12月 29, 2016
作者:
L
Luo Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
finish 1st version of machine translation
上级
f4093903
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
342 addition
and
282 deletion
+342
-282
machine_translation/README.md
machine_translation/README.md
+327
-265
machine_translation/image/bi_rnn.png
machine_translation/image/bi_rnn.png
+0
-0
machine_translation/image/decoder_attention.png
machine_translation/image/decoder_attention.png
+0
-0
machine_translation/image/encoder_attention.PNG
machine_translation/image/encoder_attention.PNG
+0
-0
machine_translation/image/gru.PNG
machine_translation/image/gru.PNG
+0
-0
machine_translation/seqToseq_net.py
machine_translation/seqToseq_net.py
+15
-17
未找到文件。
machine_translation/README.md
浏览文件 @
eddf9bac
此差异已折叠。
点击以展开。
machine_translation/image/bi_rnn.png
0 → 100644
浏览文件 @
eddf9bac
53.1 KB
machine_translation/image/decoder_attention.png
0 → 100644
浏览文件 @
eddf9bac
87.6 KB
machine_translation/image/encoder_attention.PNG
已删除
100644 → 0
浏览文件 @
f4093903
52.0 KB
machine_translation/image/gru.PNG
已删除
100644 → 0
浏览文件 @
f4093903
46.1 KB
machine_translation/seqToseq_net.py
浏览文件 @
eddf9bac
...
...
@@ -43,20 +43,20 @@ define_py_data_sources2(
### Algorithm Configuration
settings
(
learning_method
=
AdamOptimizer
(),
batch_size
=
50
if
not
is_generating
else
1
,
learning_rate
=
5e-4
if
not
is_generating
else
0
)
learning_method
=
AdamOptimizer
(),
batch_size
=
50
if
not
is_generating
else
1
,
learning_rate
=
5e-4
if
not
is_generating
else
0
)
### Network Architecture
source_dict_dim
=
len
(
open
(
src_lang_dict
,
"r"
).
readlines
())
target_dict_dim
=
len
(
open
(
trg_lang_dict
,
"r"
).
readlines
())
word_vector_dim
=
512
# dimension of word vector
decoder_size
=
512
# dimension of hidden unit in GRU Decoder network
encoder_size
=
512
# dimension of hidden unit in GRU Encoder network
word_vector_dim
=
512
# dimension of word vector
decoder_size
=
512
# dimension of hidden unit in GRU Decoder network
encoder_size
=
512
# dimension of hidden unit in GRU Encoder network
if
is_generating
:
beam_size
=
3
# expand width in beam search
max_length
=
250
# a stop condition of sequence generation
beam_size
=
3
# expand width in beam search
max_length
=
250
# a stop condition of sequence generation
gen_trans_file
=
get_config_arg
(
"gen_trans_file"
,
str
,
None
)
#### Encoder
...
...
@@ -66,10 +66,10 @@ src_embedding = embedding_layer(
size
=
word_vector_dim
,
param_attr
=
ParamAttr
(
name
=
'_source_language_embedding'
))
src_forward
=
simple_gru
(
input
=
src_embedding
,
size
=
encoder_size
)
src_backward
=
simple_gru
(
input
=
src_embedding
,
size
=
encoder_size
,
reverse
=
True
)
src_backward
=
simple_gru
(
input
=
src_embedding
,
size
=
encoder_size
,
reverse
=
True
)
encoded_vector
=
concat_layer
(
input
=
[
src_forward
,
src_backward
])
#### Decoder
with
mixed_layer
(
size
=
decoder_size
)
as
encoded_proj
:
encoded_proj
+=
full_matrix_projection
(
input
=
encoded_vector
)
...
...
@@ -79,7 +79,7 @@ with mixed_layer(
act
=
TanhActivation
(),
)
as
decoder_boot
:
decoder_boot
+=
full_matrix_projection
(
input
=
backward_first
)
#### Decoder
def
gru_decoder_with_attention
(
enc_vec
,
enc_proj
,
current_word
):
decoder_mem
=
memory
(
name
=
'gru_decoder'
,
size
=
decoder_size
,
boot_layer
=
decoder_boot
)
...
...
@@ -105,12 +105,11 @@ def gru_decoder_with_attention(enc_vec, enc_proj, current_word):
out
+=
full_matrix_projection
(
input
=
gru_step
)
return
out
decoder_group_name
=
"decoder_group"
group_inputs
=
[
StaticInput
(
input
=
encoded_vector
,
is_seq
=
True
),
StaticInput
(
input
=
encoded_proj
,
is_seq
=
True
)
]
group_input1
=
StaticInput
(
input
=
encoded_vector
,
is_seq
=
True
)
group_input2
=
StaticInput
(
input
=
encoded_proj
,
is_seq
=
True
)
group_inputs
=
[
group_input1
,
group_input2
]
if
not
is_generating
:
trg_embedding
=
embedding_layer
(
...
...
@@ -143,7 +142,6 @@ else:
# GeneratedInputs, which is initialized by a start mark, such as <s>,
# and must be included in generation.
trg_embedding
=
GeneratedInput
(
size
=
target_dict_dim
,
embedding_name
=
'_target_language_embedding'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录