`feeding` is devoted to specifying the correspondence between each yield record and `paddle.layer.data`. For instance, the first column of data generated by `movielens.train` corresponds to `user_id` feature.
`reader_dict` is devoted to specifying the correspondence between each yield record and `paddle.layer.data`. For instance, the first column of data generated by `movielens.train` corresponds to `user_id` feature.
```python
```python
feeding={
reader_dict={
'user_id':0,
'user_id':0,
'gender_id':1,
'gender_id':1,
'age_id':2,
'age_id':2,
...
@@ -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
defevent_handler(event):
ifisinstance(event,paddle.event.EndIteration):
ifevent.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=[],[]
defevent_handler(event):
defevent_handler_plot(event):
globalstep
globalstep
globaltrain_costs
globaltrain_costs
globaltest_costs
globaltest_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:
`feeding` is devoted to specifying the correspondence between each yield record and `paddle.layer.data`. For instance, the first column of data generated by `movielens.train` corresponds to `user_id` feature.
`reader_dict` is devoted to specifying the correspondence between each yield record and `paddle.layer.data`. For instance, the first column of data generated by `movielens.train` corresponds to `user_id` feature.
```python
```python
feeding = {
reader_dict = {
'user_id': 0,
'user_id': 0,
'gender_id': 1,
'gender_id': 1,
'age_id': 2,
'age_id': 2,
...
@@ -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: