Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
b1ab60da
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看板
提交
b1ab60da
编写于
5月 10, 2017
作者:
W
wwhu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adjust some comments
上级
bb93d5c0
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
20 addition
and
29 deletion
+20
-29
scheduled_sampling/random_schedule_generator.py
scheduled_sampling/random_schedule_generator.py
+19
-28
scheduled_sampling/scheduled_sampling.py
scheduled_sampling/scheduled_sampling.py
+1
-1
未找到文件。
scheduled_sampling/random_schedule_generator.py
浏览文件 @
b1ab60da
import
numpy
as
np
import
numpy
as
np
import
math
import
math
import
pdb
'''
The random sampling rate for scheduled sampling algoithm, which uses devcayed
sampling rate.
'''
class
RandomScheduleGenerator
:
class
RandomScheduleGenerator
:
'''
"""
The random sampling rate for scheduled sampling algoithm, which uses devcayed
sampling rate.
"""
def
__init__
(
self
,
schedule_type
,
a
,
b
):
"""
schduled_type: is the type of the decay. It supports constant, linear,
schduled_type: is the type of the decay. It supports constant, linear,
exponential, and inverse_sigmoid right now.
exponential, and inverse_sigmoid right now.
a: parameter of the decay (MUST BE DOUBLE)
a: parameter of the decay (MUST BE DOUBLE)
b: parameter of the decay (MUST BE DOUBLE)
b: parameter of the decay (MUST BE DOUBLE)
'''
"""
def
__init__
(
self
,
schedule_type
,
a
,
b
):
self
.
schedule_type
=
schedule_type
self
.
schedule_type
=
schedule_type
self
.
a
=
a
self
.
a
=
a
self
.
b
=
b
self
.
b
=
b
...
@@ -24,33 +23,25 @@ class RandomScheduleGenerator:
...
@@ -24,33 +23,25 @@ class RandomScheduleGenerator:
"constant"
:
lambda
a
,
b
,
d
:
a
,
"constant"
:
lambda
a
,
b
,
d
:
a
,
"linear"
:
lambda
a
,
b
,
d
:
max
(
a
,
1
-
d
/
b
),
"linear"
:
lambda
a
,
b
,
d
:
max
(
a
,
1
-
d
/
b
),
"exponential"
:
lambda
a
,
b
,
d
:
pow
(
a
,
d
/
b
),
"exponential"
:
lambda
a
,
b
,
d
:
pow
(
a
,
d
/
b
),
"inverse_sigmoid"
:
lambda
a
,
b
,
d
:
b
/
(
b
+
exp
(
d
*
a
/
b
)),
"inverse_sigmoid"
:
lambda
a
,
b
,
d
:
b
/
(
b
+
math
.
exp
(
d
*
a
/
b
)),
}
}
assert
(
self
.
schedule_type
in
self
.
schedule_computers
)
assert
(
self
.
schedule_type
in
self
.
schedule_computers
)
self
.
schedule_computer
=
self
.
schedule_computers
[
self
.
schedule_type
]
self
.
schedule_computer
=
self
.
schedule_computers
[
self
.
schedule_type
]
'''
Get the schedule sampling rate. Usually not needed to be called by the users
'''
def
getScheduleRate
(
self
):
def
getScheduleRate
(
self
):
"""
Get the schedule sampling rate. Usually not needed to be called by the users
"""
return
self
.
schedule_computer
(
self
.
a
,
self
.
b
,
self
.
data_processed_
)
return
self
.
schedule_computer
(
self
.
a
,
self
.
b
,
self
.
data_processed_
)
'''
def
processBatch
(
self
,
batch_size
):
"""
Get a batch_size of sampled indexes. These indexes can be passed to a
Get a batch_size of sampled indexes. These indexes can be passed to a
MultiplexLayer to select from the grouth truth and generated samples
MultiplexLayer to select from the grouth truth and generated samples
from the last time step.
from the last time step.
'''
"""
def
processBatch
(
self
,
batch_size
):
rate
=
self
.
getScheduleRate
()
rate
=
self
.
getScheduleRate
()
numbers
=
np
.
random
.
rand
(
batch_size
)
numbers
=
np
.
random
.
rand
(
batch_size
)
indexes
=
(
numbers
>=
rate
).
astype
(
'int32'
).
tolist
()
indexes
=
(
numbers
>=
rate
).
astype
(
'int32'
).
tolist
()
self
.
data_processed_
+=
batch_size
self
.
data_processed_
+=
batch_size
return
indexes
return
indexes
if
__name__
==
"__main__"
:
schedule_generator
=
RandomScheduleGenerator
(
"linear"
,
0.1
,
500000
)
true_token_flag
=
schedule_generator
.
processBatch
(
5
)
pdb
.
set_trace
()
scheduled_sampling/scheduled_sampling.py
浏览文件 @
b1ab60da
...
@@ -74,7 +74,7 @@ def seqToseq_net(source_dict_dim, target_dict_dim, is_generating=False):
...
@@ -74,7 +74,7 @@ def seqToseq_net(source_dict_dim, target_dict_dim, is_generating=False):
decoder_state
=
decoder_mem
)
decoder_state
=
decoder_mem
)
gru_out_memory
=
paddle
.
layer
.
memory
(
gru_out_memory
=
paddle
.
layer
.
memory
(
name
=
'gru_out'
,
size
=
target_dict_dim
)
# , boot_with_const_id=0)
name
=
'gru_out'
,
size
=
target_dict_dim
)
generated_word
=
paddle
.
layer
.
max_id
(
input
=
gru_out_memory
)
generated_word
=
paddle
.
layer
.
max_id
(
input
=
gru_out_memory
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录