Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
9efd9a03
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看板
提交
9efd9a03
编写于
4月 26, 2017
作者:
G
gangliao
提交者:
GitHub
4月 26, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #304 from QiJune/feature/refine_08_demo
update event_handler
上级
ab35852f
3e27398d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
68 addition
and
34 deletion
+68
-34
08.recommender_system/README.en.md
08.recommender_system/README.en.md
+12
-4
08.recommender_system/README.md
08.recommender_system/README.md
+22
-13
08.recommender_system/index.en.html
08.recommender_system/index.en.html
+12
-4
08.recommender_system/index.html
08.recommender_system/index.html
+22
-13
未找到文件。
08.recommender_system/README.en.md
浏览文件 @
9efd9a03
...
@@ -315,7 +315,15 @@ feeding = {
...
@@ -315,7 +315,15 @@ feeding = {
}
}
```
```
Callback function
`event_handler`
will be called during training when a pre-defined event happens.
Callback function
`event_handler`
and
`event_handler_plot`
will be called during training when a pre-defined event happens.
```
python
def
event_handler
(
event
):
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
if
event
.
batch_id
%
100
==
0
:
print
"Pass %d Batch %d Cost %.2f"
%
(
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
)
```
```
python
```
python
step
=
0
step
=
0
...
@@ -323,7 +331,7 @@ step=0
...
@@ -323,7 +331,7 @@ step=0
train_costs
=
[],[]
train_costs
=
[],[]
test_costs
=
[],[]
test_costs
=
[],[]
def
event_handler
(
event
):
def
event_handler
_plot
(
event
):
global
step
global
step
global
train_costs
global
train_costs
global
test_costs
global
test_costs
...
@@ -354,9 +362,9 @@ Finally, we can invoke `trainer.train` to start training:
...
@@ -354,9 +362,9 @@ Finally, we can invoke `trainer.train` to start training:
```
python
```
python
trainer
.
train
(
trainer
.
train
(
reader
=
reader
,
reader
=
reader
,
event_handler
=
event_handler
,
event_handler
=
event_handler
_plot
,
feeding
=
feeding
,
feeding
=
feeding
,
num_passes
=
2
00
)
num_passes
=
2
)
```
```
## Conclusion
## Conclusion
...
...
08.recommender_system/README.md
浏览文件 @
9efd9a03
...
@@ -321,20 +321,11 @@ trainer = paddle.trainer.SGD(cost=cost, parameters=parameters,
...
@@ -321,20 +321,11 @@ trainer = paddle.trainer.SGD(cost=cost, parameters=parameters,
下面我们开始训练过程。
下面我们开始训练过程。
我们直接使用Paddle提供的数据集读取程序。
`paddle.dataset.movielens.train()`
和
`paddle.dataset.movielens.test()`
分别做训练和预测数据集。并且通过
`reader_dict`
来指定每一个数据和data_layer的对应关系。
我们直接使用Paddle提供的数据集读取程序。
`paddle.dataset.movielens.train()`
和
`paddle.dataset.movielens.test()`
分别做训练和预测数据集。并且通过
`feeding`
来指定每一个数据和data_layer的对应关系。
例如,这里的reader_dict表示的是,对于数据层
`user_id`
,使用了reader中每一条数据的第0个元素。
`gender_id`
数据层使用了第1个元素。以此类推。
训练过程是完全自动的。我们可以使用event_handler来观察训练过程,或进行测试等。这里我们在event_handler里面绘制了训练误差曲线和测试误差曲线。并且保存了模型。
例如,这里的feeding表示的是,对于数据层
`user_id`
,使用了reader中每一条数据的第0个元素。
`gender_id`
数据层使用了第1个元素。以此类推。
```
python
```
python
%
matplotlib
inline
import
matplotlib.pyplot
as
plt
from
IPython
import
display
import
cPickle
feeding
=
{
feeding
=
{
'user_id'
:
0
,
'user_id'
:
0
,
'gender_id'
:
1
,
'gender_id'
:
1
,
...
@@ -345,13 +336,31 @@ feeding = {
...
@@ -345,13 +336,31 @@ feeding = {
'movie_title'
:
6
,
'movie_title'
:
6
,
'score'
:
7
'score'
:
7
}
}
```
训练过程是完全自动的。我们可以使用event_handler与event_handler_plot来观察训练过程,或进行测试等。这里我们在event_handler_plot里面绘制了训练误差曲线和测试误差曲线。并且保存了模型。
```
python
def
event_handler
(
event
):
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
if
event
.
batch_id
%
100
==
0
:
print
"Pass %d Batch %d Cost %.2f"
%
(
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
)
```
```
python
%
matplotlib
inline
import
matplotlib.pyplot
as
plt
from
IPython
import
display
import
cPickle
step
=
0
step
=
0
train_costs
=
[],[]
train_costs
=
[],[]
test_costs
=
[],[]
test_costs
=
[],[]
def
event_handler
(
event
):
def
event_handler
_plot
(
event
):
global
step
global
step
global
train_costs
global
train_costs
global
test_costs
global
test_costs
...
@@ -381,7 +390,7 @@ trainer.train(
...
@@ -381,7 +390,7 @@ trainer.train(
paddle
.
reader
.
shuffle
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
movielens
.
train
(),
buf_size
=
8192
),
paddle
.
dataset
.
movielens
.
train
(),
buf_size
=
8192
),
batch_size
=
256
),
batch_size
=
256
),
event_handler
=
event_handler
,
event_handler
=
event_handler
_plot
,
feeding
=
feeding
,
feeding
=
feeding
,
num_passes
=
2
)
num_passes
=
2
)
```
```
...
...
08.recommender_system/index.en.html
浏览文件 @
9efd9a03
...
@@ -357,7 +357,15 @@ feeding = {
...
@@ -357,7 +357,15 @@ feeding = {
}
}
```
```
Callback function `event_handler` will be called during training when a pre-defined event happens.
Callback function `event_handler` and `event_handler_plot` will be called during training when a pre-defined event happens.
```python
def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
print "Pass %d Batch %d Cost %.2f" % (
event.pass_id, event.batch_id, event.cost)
```
```python
```python
step=0
step=0
...
@@ -365,7 +373,7 @@ step=0
...
@@ -365,7 +373,7 @@ step=0
train_costs=[],[]
train_costs=[],[]
test_costs=[],[]
test_costs=[],[]
def event_handler(event):
def event_handler
_plot
(event):
global step
global step
global train_costs
global train_costs
global test_costs
global test_costs
...
@@ -396,9 +404,9 @@ Finally, we can invoke `trainer.train` to start training:
...
@@ -396,9 +404,9 @@ Finally, we can invoke `trainer.train` to start training:
```python
```python
trainer.train(
trainer.train(
reader=reader,
reader=reader,
event_handler=event_handler,
event_handler=event_handler
_plot
,
feeding=feeding,
feeding=feeding,
num_passes=2
00
)
num_passes=2)
```
```
## Conclusion
## Conclusion
...
...
08.recommender_system/index.html
浏览文件 @
9efd9a03
...
@@ -363,20 +363,11 @@ trainer = paddle.trainer.SGD(cost=cost, parameters=parameters,
...
@@ -363,20 +363,11 @@ trainer = paddle.trainer.SGD(cost=cost, parameters=parameters,
下面我们开始训练过程。
下面我们开始训练过程。
我们直接使用Paddle提供的数据集读取程序。`paddle.dataset.movielens.train()`和`paddle.dataset.movielens.test()`分别做训练和预测数据集。并且通过`reader_dict`来指定每一个数据和data_layer的对应关系。
我们直接使用Paddle提供的数据集读取程序。`paddle.dataset.movielens.train()`和`paddle.dataset.movielens.test()`分别做训练和预测数据集。并且通过`feeding`来指定每一个数据和data_layer的对应关系。
例如,这里的reader_dict表示的是,对于数据层 `user_id`,使用了reader中每一条数据的第0个元素。`gender_id`数据层使用了第1个元素。以此类推。
训练过程是完全自动的。我们可以使用event_handler来观察训练过程,或进行测试等。这里我们在event_handler里面绘制了训练误差曲线和测试误差曲线。并且保存了模型。
例如,这里的feeding表示的是,对于数据层 `user_id`,使用了reader中每一条数据的第0个元素。`gender_id`数据层使用了第1个元素。以此类推。
```python
```python
%matplotlib inline
import matplotlib.pyplot as plt
from IPython import display
import cPickle
feeding = {
feeding = {
'user_id': 0,
'user_id': 0,
'gender_id': 1,
'gender_id': 1,
...
@@ -387,13 +378,31 @@ feeding = {
...
@@ -387,13 +378,31 @@ feeding = {
'movie_title': 6,
'movie_title': 6,
'score': 7
'score': 7
}
}
```
训练过程是完全自动的。我们可以使用event_handler与event_handler_plot来观察训练过程,或进行测试等。这里我们在event_handler_plot里面绘制了训练误差曲线和测试误差曲线。并且保存了模型。
```python
def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
print "Pass %d Batch %d Cost %.2f" % (
event.pass_id, event.batch_id, event.cost)
```
```python
%matplotlib inline
import matplotlib.pyplot as plt
from IPython import display
import cPickle
step=0
step=0
train_costs=[],[]
train_costs=[],[]
test_costs=[],[]
test_costs=[],[]
def event_handler(event):
def event_handler
_plot
(event):
global step
global step
global train_costs
global train_costs
global test_costs
global test_costs
...
@@ -423,7 +432,7 @@ trainer.train(
...
@@ -423,7 +432,7 @@ trainer.train(
paddle.reader.shuffle(
paddle.reader.shuffle(
paddle.dataset.movielens.train(), buf_size=8192),
paddle.dataset.movielens.train(), buf_size=8192),
batch_size=256),
batch_size=256),
event_handler=event_handler,
event_handler=event_handler
_plot
,
feeding=feeding,
feeding=feeding,
num_passes=2)
num_passes=2)
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录