Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
c26aa060
B
book
项目概览
PaddlePaddle
/
book
通知
16
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c26aa060
编写于
10月 09, 2018
作者:
Q
Qiyang Min
提交者:
GitHub
10月 09, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #625 from velconia/port_py3
Port current book code and doc to python3
上级
5596f274
6ba1445a
变更
29
隐藏空白更改
内联
并排
Showing
29 changed file
with
88 addition
and
95 deletion
+88
-95
01.fit_a_line/README.cn.md
01.fit_a_line/README.cn.md
+5
-9
01.fit_a_line/README.md
01.fit_a_line/README.md
+6
-10
01.fit_a_line/image/ranges.png
01.fit_a_line/image/ranges.png
+0
-0
01.fit_a_line/index.cn.html
01.fit_a_line/index.cn.html
+5
-9
01.fit_a_line/index.html
01.fit_a_line/index.html
+6
-10
01.fit_a_line/train.py
01.fit_a_line/train.py
+6
-10
03.image_classification/README.cn.md
03.image_classification/README.cn.md
+1
-1
03.image_classification/README.md
03.image_classification/README.md
+1
-1
03.image_classification/index.cn.html
03.image_classification/index.cn.html
+1
-1
03.image_classification/index.html
03.image_classification/index.html
+1
-1
03.image_classification/resnet.py
03.image_classification/resnet.py
+1
-1
03.image_classification/train.py
03.image_classification/train.py
+1
-1
04.word2vec/README.cn.md
04.word2vec/README.cn.md
+2
-1
04.word2vec/README.md
04.word2vec/README.md
+2
-1
04.word2vec/index.cn.html
04.word2vec/index.cn.html
+2
-1
04.word2vec/index.html
04.word2vec/index.html
+2
-1
04.word2vec/train.py
04.word2vec/train.py
+3
-2
06.understand_sentiment/README.cn.md
06.understand_sentiment/README.cn.md
+1
-1
06.understand_sentiment/README.md
06.understand_sentiment/README.md
+1
-1
06.understand_sentiment/index.cn.html
06.understand_sentiment/index.cn.html
+1
-1
06.understand_sentiment/index.html
06.understand_sentiment/index.html
+1
-1
06.understand_sentiment/train_conv.py
06.understand_sentiment/train_conv.py
+8
-7
06.understand_sentiment/train_dyn_rnn.py
06.understand_sentiment/train_dyn_rnn.py
+8
-7
06.understand_sentiment/train_stacked_lstm.py
06.understand_sentiment/train_stacked_lstm.py
+8
-7
07.label_semantic_roles/README.cn.md
07.label_semantic_roles/README.cn.md
+3
-2
07.label_semantic_roles/README.md
07.label_semantic_roles/README.md
+3
-2
07.label_semantic_roles/index.cn.html
07.label_semantic_roles/index.cn.html
+3
-2
07.label_semantic_roles/index.html
07.label_semantic_roles/index.html
+3
-2
07.label_semantic_roles/train.py
07.label_semantic_roles/train.py
+3
-2
未找到文件。
01.fit_a_line/README.cn.md
浏览文件 @
c26aa060
...
...
@@ -183,26 +183,22 @@ feed_order=['x', 'y']
# Specify the directory to save the parameters
params_dirname
=
"fit_a_line.inference.model"
# Plot data
from
paddle.v2.plot
import
Ploter
train_title
=
"Train cost"
test_title
=
"Test cost"
plot_cost
=
Ploter
(
train_title
,
test_title
)
step
=
0
# event_handler prints training and testing info
def
event_handler
_plot
(
event
):
def
event_handler
(
event
):
global
step
if
isinstance
(
event
,
fluid
.
contrib
.
trainer
.
EndStepEvent
):
if
step
%
10
==
0
:
# record a train cost every 10 batches
p
lot_cost
.
append
(
train_title
,
step
,
event
.
metrics
[
0
]
)
p
rint
(
"%s, Step %d, Cost %f"
%
(
train_title
,
step
,
event
.
metrics
[
0
])
)
if
step
%
100
==
0
:
# record a test cost every 100 batches
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
feed_order
)
plot_cost
.
append
(
test_title
,
step
,
test_metrics
[
0
])
plot_cost
.
plot
()
print
(
"%s, Step %d, Cost %f"
%
(
test_title
,
step
,
test_metrics
[
0
]))
if
test_metrics
[
0
]
<
10.0
:
# If the accuracy is good enough, we can stop the training.
...
...
@@ -227,7 +223,7 @@ def event_handler_plot(event):
trainer
.
train
(
reader
=
train_reader
,
num_epochs
=
100
,
event_handler
=
event_handler
_plot
,
event_handler
=
event_handler
,
feed_order
=
feed_order
)
```
<div
align=
"center"
>
...
...
@@ -259,7 +255,7 @@ inferencer = fluid.contrib.inferencer.Inferencer(
batch_size
=
10
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
uci_housing
.
test
(),
batch_size
=
batch_size
)
test_data
=
test_reader
().
next
(
)
test_data
=
next
(
test_reader
()
)
test_x
=
numpy
.
array
([
data
[
0
]
for
data
in
test_data
]).
astype
(
"float32"
)
test_y
=
numpy
.
array
([
data
[
1
]
for
data
in
test_data
]).
astype
(
"float32"
)
...
...
01.fit_a_line/README.md
浏览文件 @
c26aa060
...
...
@@ -202,26 +202,22 @@ Moreover, an event handler is provided to print the training progress:
# Specify the directory to save the parameters
params_dirname
=
"fit_a_line.inference.model"
# Plot data
from
paddle.v2.plot
import
Ploter
train_title
=
"Train cost"
test_title
=
"Test cost"
plot_cost
=
Ploter
(
train_title
,
test_title
)
step
=
0
# event_handler prints training and testing info
def
event_handler
_plot
(
event
):
def
event_handler
(
event
):
global
step
if
isinstance
(
event
,
fluid
.
contrib
.
trainer
.
EndStepEvent
):
if
step
%
10
==
0
:
# record a train cost every 10 batches
p
lot_cost
.
append
(
train_title
,
step
,
event
.
metrics
[
0
]
)
p
rint
(
"%s, Step %d, Cost %f"
%
(
train_title
,
step
,
event
.
metrics
[
0
])
)
if
step
%
100
==
0
:
# record a test cost every 100 batches
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
feed_order
)
plot_cost
.
append
(
test_title
,
step
,
test_metrics
[
0
])
plot_cost
.
plot
()
print
(
"%s, Step %d, Cost %f"
%
(
test_title
,
step
,
test_metrics
[
0
]))
if
test_metrics
[
0
]
<
10.0
:
# If the accuracy is good enough, we can stop the training.
...
...
@@ -229,7 +225,7 @@ def event_handler_plot(event):
trainer
.
stop
()
step
+=
1
if
isinstance
(
event
,
fluid
.
contrib
.
trainer
.
EndEpochEvent
):
if
isinstance
(
event
,
EndEpochEvent
):
if
event
.
epoch
%
10
==
0
:
# We can save the trained parameters for the inferences later
if
params_dirname
is
not
None
:
...
...
@@ -248,7 +244,7 @@ We now can start training by calling `trainer.train()`.
trainer
.
train
(
reader
=
train_reader
,
num_epochs
=
100
,
event_handler
=
event_handler
_plot
,
event_handler
=
event_handler
,
feed_order
=
feed_order
)
```
...
...
@@ -281,7 +277,7 @@ inferencer = fluid.contrib.inferencer.Inferencer(
batch_size
=
10
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
uci_housing
.
test
(),
batch_size
=
batch_size
)
test_data
=
test_reader
().
next
(
)
test_data
=
next
(
test_reader
()
)
test_x
=
numpy
.
array
([
data
[
0
]
for
data
in
test_data
]).
astype
(
"float32"
)
test_y
=
numpy
.
array
([
data
[
1
]
for
data
in
test_data
]).
astype
(
"float32"
)
...
...
01.fit_a_line/image/ranges.png
查看替换文件 @
5596f274
浏览文件 @
c26aa060
6.6 KB
|
W:
|
H:
6.6 KB
|
W:
|
H:
2-up
Swipe
Onion skin
01.fit_a_line/index.cn.html
浏览文件 @
c26aa060
...
...
@@ -225,26 +225,22 @@ feed_order=['x', 'y']
# Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model"
# Plot data
from paddle.v2.plot import Ploter
train_title = "Train cost"
test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)
step = 0
# event_handler prints training and testing info
def event_handler
_plot
(event):
def event_handler(event):
global step
if isinstance(event, fluid.contrib.trainer.EndStepEvent):
if step % 10 == 0: # record a train cost every 10 batches
p
lot_cost.append(train_title, step, event.metrics[0]
)
p
rint("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0])
)
if step % 100 == 0: # record a test cost every 100 batches
test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order)
plot_cost.append(test_title, step, test_metrics[0])
plot_cost.plot()
print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0]))
if test_metrics[0]
<
10.0
:
#
If
the
accuracy
is
good
enough
,
we
can
stop
the
training.
...
...
@@ -269,7 +265,7 @@ def event_handler_plot(event):
trainer.train
(
reader=
train_reader,
num_epochs=
100,
event_handler=
event_handler
_plot
,
event_handler=
event_handler,
feed_order=
feed_order)
```
<
div
align=
"center"
>
...
...
@@ -301,7 +297,7 @@ inferencer = fluid.contrib.inferencer.Inferencer(
batch_size = 10
test_reader = paddle.batch(paddle.dataset.uci_housing.test(),batch_size=batch_size)
test_data =
test_reader().next(
)
test_data =
next(test_reader()
)
test_x = numpy.array([data[0] for data in test_data]).astype("float32")
test_y = numpy.array([data[1] for data in test_data]).astype("float32")
...
...
01.fit_a_line/index.html
浏览文件 @
c26aa060
...
...
@@ -244,26 +244,22 @@ Moreover, an event handler is provided to print the training progress:
# Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model"
# Plot data
from paddle.v2.plot import Ploter
train_title = "Train cost"
test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)
step = 0
# event_handler prints training and testing info
def event_handler
_plot
(event):
def event_handler(event):
global step
if isinstance(event, fluid.contrib.trainer.EndStepEvent):
if step % 10 == 0: # record a train cost every 10 batches
p
lot_cost.append(train_title, step, event.metrics[0]
)
p
rint("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0])
)
if step % 100 == 0: # record a test cost every 100 batches
test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order)
plot_cost.append(test_title, step, test_metrics[0])
plot_cost.plot()
print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0]))
if test_metrics[0]
<
10.0
:
#
If
the
accuracy
is
good
enough
,
we
can
stop
the
training.
...
...
@@ -271,7 +267,7 @@ def event_handler_plot(event):
trainer.stop
()
step
+=
1
if
isinstance
(
event
,
fluid.contrib.trainer.
EndEpochEvent
)
:
if
isinstance
(
event
,
EndEpochEvent
)
:
if
event.epoch
%
10
==
0
:
#
We
can
save
the
trained
parameters
for
the
inferences
later
if
params_dirname
is
not
None:
...
...
@@ -290,7 +286,7 @@ We now can start training by calling `trainer.train()`.
trainer.train
(
reader=
train_reader,
num_epochs=
100,
event_handler=
event_handler
_plot
,
event_handler=
event_handler,
feed_order=
feed_order)
```
...
...
@@ -323,7 +319,7 @@ inferencer = fluid.contrib.inferencer.Inferencer(
batch_size =
10
test_reader =
paddle.batch(paddle.dataset.uci_housing.test(),batch_size=batch_size)
test_data =
test_reader().next(
)
test_data =
next(test_reader()
)
test_x =
numpy.array([data[0]
for
data
in
test_data
]).
astype
("
float32
")
test_y =
numpy.array([data[1]
for
data
in
test_data
]).
astype
("
float32
")
...
...
01.fit_a_line/train.py
浏览文件 @
c26aa060
...
...
@@ -69,28 +69,24 @@ feed_order = ['x', 'y']
# Specify the directory to save the parameters
params_dirname
=
"fit_a_line.inference.model"
# Plot data
from
paddle.v2.plot
import
Ploter
train_title
=
"Train cost"
test_title
=
"Test cost"
plot_cost
=
Ploter
(
train_title
,
test_title
)
step
=
0
# event_handler prints training and testing info
def
event_handler
_plot
(
event
):
def
event_handler
(
event
):
global
step
if
isinstance
(
event
,
EndStepEvent
):
if
step
%
10
==
0
:
# record a train cost every 10 batches
plot_cost
.
append
(
train_title
,
step
,
event
.
metrics
[
0
])
print
(
"%s, Step %d, Cost %f"
%
(
train_title
,
step
,
event
.
metrics
[
0
]))
if
step
%
100
==
0
:
# record a test cost every 100 batches
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
feed_order
)
plot_cost
.
append
(
test_title
,
step
,
test_metrics
[
0
])
plot_cost
.
plot
()
print
(
"%s, Step %d, Cost %f"
%
(
test_title
,
step
,
test_metrics
[
0
]))
if
test_metrics
[
0
]
<
10.0
:
# If the accuracy is good enough, we can stop the training.
...
...
@@ -109,7 +105,7 @@ def event_handler_plot(event):
trainer
.
train
(
reader
=
train_reader
,
num_epochs
=
100
,
event_handler
=
event_handler
_plot
,
event_handler
=
event_handler
,
feed_order
=
feed_order
)
...
...
@@ -125,7 +121,7 @@ inferencer = Inferencer(
batch_size
=
10
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
uci_housing
.
test
(),
batch_size
=
batch_size
)
test_data
=
test_reader
().
next
(
)
test_data
=
next
(
test_reader
()
)
test_x
=
numpy
.
array
([
data
[
0
]
for
data
in
test_data
]).
astype
(
"float32"
)
test_y
=
numpy
.
array
([
data
[
1
]
for
data
in
test_data
]).
astype
(
"float32"
)
...
...
03.image_classification/README.cn.md
浏览文件 @
c26aa060
...
...
@@ -282,7 +282,7 @@ def layer_warp(block_func, input, ch_in, ch_out, count, stride):
def
resnet_cifar10
(
ipt
,
depth
=
32
):
# depth should be one of 20, 32, 44, 56, 110, 1202
assert
(
depth
-
2
)
%
6
==
0
n
=
(
depth
-
2
)
/
6
n
=
(
depth
-
2
)
/
/
6
nStages
=
{
16
,
64
,
128
}
conv1
=
conv_bn_layer
(
ipt
,
ch_out
=
16
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
res1
=
layer_warp
(
basicblock
,
conv1
,
16
,
16
,
n
,
1
)
...
...
03.image_classification/README.md
浏览文件 @
c26aa060
...
...
@@ -282,7 +282,7 @@ Note: besides the first convolutional layer and the last fully-connected layer,
def
resnet_cifar10
(
ipt
,
depth
=
32
):
# depth should be one of 20, 32, 44, 56, 110, 1202
assert
(
depth
-
2
)
%
6
==
0
n
=
(
depth
-
2
)
/
6
n
=
(
depth
-
2
)
/
/
6
nStages
=
{
16
,
64
,
128
}
conv1
=
conv_bn_layer
(
ipt
,
ch_out
=
16
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
res1
=
layer_warp
(
basicblock
,
conv1
,
16
,
16
,
n
,
1
)
...
...
03.image_classification/index.cn.html
浏览文件 @
c26aa060
...
...
@@ -324,7 +324,7 @@ def layer_warp(block_func, input, ch_in, ch_out, count, stride):
def resnet_cifar10(ipt, depth=32):
# depth should be one of 20, 32, 44, 56, 110, 1202
assert (depth - 2) % 6 == 0
n = (depth - 2) / 6
n = (depth - 2) /
/
6
nStages = {16, 64, 128}
conv1 = conv_bn_layer(ipt, ch_out=16, filter_size=3, stride=1, padding=1)
res1 = layer_warp(basicblock, conv1, 16, 16, n, 1)
...
...
03.image_classification/index.html
浏览文件 @
c26aa060
...
...
@@ -324,7 +324,7 @@ Note: besides the first convolutional layer and the last fully-connected layer,
def resnet_cifar10(ipt, depth=32):
# depth should be one of 20, 32, 44, 56, 110, 1202
assert (depth - 2) % 6 == 0
n = (depth - 2) / 6
n = (depth - 2) /
/
6
nStages = {16, 64, 128}
conv1 = conv_bn_layer(ipt, ch_out=16, filter_size=3, stride=1, padding=1)
res1 = layer_warp(basicblock, conv1, 16, 16, n, 1)
...
...
03.image_classification/resnet.py
浏览文件 @
c26aa060
...
...
@@ -70,7 +70,7 @@ def layer_warp(block_func, input, ch_in, ch_out, count, stride):
def
resnet_cifar10
(
ipt
,
depth
=
32
):
# depth should be one of 20, 32, 44, 56, 110, 1202
assert
(
depth
-
2
)
%
6
==
0
n
=
(
depth
-
2
)
/
6
n
=
(
depth
-
2
)
/
/
6
nStages
=
{
16
,
64
,
128
}
conv1
=
conv_bn_layer
(
ipt
,
ch_out
=
16
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
res1
=
layer_warp
(
basicblock
,
conv1
,
16
,
16
,
n
,
1
)
...
...
03.image_classification/train.py
浏览文件 @
c26aa060
...
...
@@ -102,7 +102,7 @@ def infer(use_cuda, inference_program, params_dirname=None):
inferencer
=
Inferencer
(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
# Prepare testing data.
# Prepare testing data.
from
PIL
import
Image
import
numpy
as
np
import
os
...
...
04.word2vec/README.cn.md
浏览文件 @
c26aa060
...
...
@@ -208,6 +208,7 @@ import numpy
from
functools
import
partial
import
math
import
os
import
six
import
sys
from
__future__
import
print_function
```
...
...
@@ -394,7 +395,7 @@ def infer(use_cuda, inference_program, params_dirname=None):
most_possible_word_index
=
numpy
.
argmax
(
result
[
0
])
print
(
most_possible_word_index
)
print
([
key
for
key
,
value
in
word_dict
.
iteritems
(
)
key
for
key
,
value
in
six
.
iteritems
(
word_dict
)
if
value
==
most_possible_word_index
][
0
])
```
...
...
04.word2vec/README.md
浏览文件 @
c26aa060
...
...
@@ -221,6 +221,7 @@ import numpy
from
functools
import
partial
import
math
import
os
import
six
import
sys
from
__future__
import
print_function
```
...
...
@@ -412,7 +413,7 @@ def infer(use_cuda, inference_program, params_dirname=None):
most_possible_word_index
=
numpy
.
argmax
(
result
[
0
])
print
(
most_possible_word_index
)
print
([
key
for
key
,
value
in
word_dict
.
iteritems
(
)
key
for
key
,
value
in
six
.
iteritems
(
word_dict
)
if
value
==
most_possible_word_index
][
0
])
```
...
...
04.word2vec/index.cn.html
浏览文件 @
c26aa060
...
...
@@ -250,6 +250,7 @@ import numpy
from functools import partial
import math
import os
import six
import sys
from __future__ import print_function
```
...
...
@@ -436,7 +437,7 @@ def infer(use_cuda, inference_program, params_dirname=None):
most_possible_word_index = numpy.argmax(result[0])
print(most_possible_word_index)
print([
key for key, value in
word_dict.iteritems(
)
key for key, value in
six.iteritems(word_dict
)
if value == most_possible_word_index
][0])
```
...
...
04.word2vec/index.html
浏览文件 @
c26aa060
...
...
@@ -263,6 +263,7 @@ import numpy
from functools import partial
import math
import os
import six
import sys
from __future__ import print_function
```
...
...
@@ -454,7 +455,7 @@ def infer(use_cuda, inference_program, params_dirname=None):
most_possible_word_index =
numpy.argmax(result[0])
print
(
most_possible_word_index
)
print
([
key
for
key
,
value
in
word_dict.iteritems
(
)
key
for
key
,
value
in
six.iteritems
(
word_dict
)
if
value =
=
most_possible_word_index
][0])
```
...
...
04.word2vec/train.py
浏览文件 @
c26aa060
...
...
@@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
import
paddle
.v2
as
paddle
import
paddle
as
paddle
import
paddle.fluid
as
fluid
import
six
import
sys
try
:
...
...
@@ -176,7 +177,7 @@ def infer(use_cuda, inference_program, params_dirname=None):
most_possible_word_index
=
numpy
.
argmax
(
result
[
0
])
print
(
most_possible_word_index
)
print
([
key
for
key
,
value
in
word_dict
.
iteritems
(
)
key
for
key
,
value
in
six
.
iteritems
(
word_dict
)
if
value
==
most_possible_word_index
][
0
])
...
...
06.understand_sentiment/README.cn.md
浏览文件 @
c26aa060
...
...
@@ -274,7 +274,7 @@ params_dirname = "understand_sentiment_conv.inference.model"
def
event_handler
(
event
):
if
isinstance
(
event
,
fluid
.
contrib
.
trainer
.
EndStepEvent
):
print
(
"Step {0}, Epoch {1} Metrics {2}"
.
format
(
event
.
step
,
event
.
epoch
,
map
(
np
.
array
,
event
.
metrics
)))
event
.
step
,
event
.
epoch
,
list
(
map
(
np
.
array
,
event
.
metrics
)
)))
if
event
.
step
==
10
:
trainer
.
save_params
(
params_dirname
)
...
...
06.understand_sentiment/README.md
浏览文件 @
c26aa060
...
...
@@ -281,7 +281,7 @@ params_dirname = "understand_sentiment_conv.inference.model"
def
event_handler
(
event
):
if
isinstance
(
event
,
fluid
.
contrib
.
trainer
.
EndStepEvent
):
print
(
"Step {0}, Epoch {1} Metrics {2}"
.
format
(
event
.
step
,
event
.
epoch
,
map
(
np
.
array
,
event
.
metrics
)))
event
.
step
,
event
.
epoch
,
list
(
map
(
np
.
array
,
event
.
metrics
)
)))
if
event
.
step
==
10
:
trainer
.
save_params
(
params_dirname
)
...
...
06.understand_sentiment/index.cn.html
浏览文件 @
c26aa060
...
...
@@ -316,7 +316,7 @@ params_dirname = "understand_sentiment_conv.inference.model"
def event_handler(event):
if isinstance(event, fluid.contrib.trainer.EndStepEvent):
print("Step {0}, Epoch {1} Metrics {2}".format(
event.step, event.epoch,
map(np.array, event.metrics
)))
event.step, event.epoch,
list(map(np.array, event.metrics)
)))
if event.step == 10:
trainer.save_params(params_dirname)
...
...
06.understand_sentiment/index.html
浏览文件 @
c26aa060
...
...
@@ -323,7 +323,7 @@ params_dirname = "understand_sentiment_conv.inference.model"
def event_handler(event):
if isinstance(event, fluid.contrib.trainer.EndStepEvent):
print("Step {0}, Epoch {1} Metrics {2}".format(
event.step, event.epoch,
map(np.array, event.metrics
)))
event.step, event.epoch,
list(map(np.array, event.metrics)
)))
if event.step == 10:
trainer.save_params(params_dirname)
...
...
06.understand_sentiment/train_conv.py
浏览文件 @
c26aa060
...
...
@@ -111,7 +111,8 @@ def train(use_cuda, train_program, params_dirname):
event
.
step
,
avg_cost
,
acc
))
print
(
"Step {0}, Epoch {1} Metrics {2}"
.
format
(
event
.
step
,
event
.
epoch
,
map
(
np
.
array
,
event
.
metrics
)))
event
.
step
,
event
.
epoch
,
list
(
map
(
np
.
array
,
event
.
metrics
))))
elif
isinstance
(
event
,
EndEpochEvent
):
trainer
.
save_params
(
params_dirname
)
...
...
@@ -133,14 +134,14 @@ def infer(use_cuda, inference_program, params_dirname=None):
place
=
place
)
# Setup input by creating LoDTensor to represent sequence of words.
# Here each word is the basic element of the LoDTensor and the shape of
# each word (base_shape) should be [1] since it is simply an index to
# Here each word is the basic element of the LoDTensor and the shape of
# each word (base_shape) should be [1] since it is simply an index to
# look up for the corresponding word vector.
# Suppose the length_based level of detail (lod) info is set to [[3, 4, 2]],
# which has only one lod level. Then the created LoDTensor will have only
# one higher level structure (sequence of words, or sentence) than the basic
# element (word). Hence the LoDTensor will hold data for three sentences of
# length 3, 4 and 2, respectively.
# which has only one lod level. Then the created LoDTensor will have only
# one higher level structure (sequence of words, or sentence) than the basic
# element (word). Hence the LoDTensor will hold data for three sentences of
# length 3, 4 and 2, respectively.
# Note that lod info should be a list of lists.
reviews_str
=
[
...
...
06.understand_sentiment/train_dyn_rnn.py
浏览文件 @
c26aa060
...
...
@@ -128,7 +128,8 @@ def train(use_cuda, train_program, params_dirname):
event
.
step
,
avg_cost
,
acc
))
print
(
"Step {0}, Epoch {1} Metrics {2}"
.
format
(
event
.
step
,
event
.
epoch
,
map
(
np
.
array
,
event
.
metrics
)))
event
.
step
,
event
.
epoch
,
list
(
map
(
np
.
array
,
event
.
metrics
))))
elif
isinstance
(
event
,
EndEpochEvent
):
trainer
.
save_params
(
params_dirname
)
...
...
@@ -150,14 +151,14 @@ def infer(use_cuda, inference_program, params_dirname=None):
place
=
place
)
# Setup input by creating LoDTensor to represent sequence of words.
# Here each word is the basic element of the LoDTensor and the shape of
# each word (base_shape) should be [1] since it is simply an index to
# Here each word is the basic element of the LoDTensor and the shape of
# each word (base_shape) should be [1] since it is simply an index to
# look up for the corresponding word vector.
# Suppose the length_based level of detail (lod) info is set to [[3, 4, 2]],
# which has only one lod level. Then the created LoDTensor will have only
# one higher level structure (sequence of words, or sentence) than the basic
# element (word). Hence the LoDTensor will hold data for three sentences of
# length 3, 4 and 2, respectively.
# which has only one lod level. Then the created LoDTensor will have only
# one higher level structure (sequence of words, or sentence) than the basic
# element (word). Hence the LoDTensor will hold data for three sentences of
# length 3, 4 and 2, respectively.
# Note that lod info should be a list of lists.
reviews_str
=
[
...
...
06.understand_sentiment/train_stacked_lstm.py
浏览文件 @
c26aa060
...
...
@@ -119,7 +119,8 @@ def train(use_cuda, train_program, params_dirname):
event
.
step
,
avg_cost
,
acc
))
print
(
"Step {0}, Epoch {1} Metrics {2}"
.
format
(
event
.
step
,
event
.
epoch
,
map
(
np
.
array
,
event
.
metrics
)))
event
.
step
,
event
.
epoch
,
list
(
map
(
np
.
array
,
event
.
metrics
))))
elif
isinstance
(
event
,
EndEpochEvent
):
trainer
.
save_params
(
params_dirname
)
...
...
@@ -141,14 +142,14 @@ def infer(use_cuda, inference_program, params_dirname=None):
place
=
place
)
# Setup input by creating LoDTensor to represent sequence of words.
# Here each word is the basic element of the LoDTensor and the shape of
# each word (base_shape) should be [1] since it is simply an index to
# Here each word is the basic element of the LoDTensor and the shape of
# each word (base_shape) should be [1] since it is simply an index to
# look up for the corresponding word vector.
# Suppose the length_based level of detail (lod) info is set to [[3, 4, 2]],
# which has only one lod level. Then the created LoDTensor will have only
# one higher level structure (sequence of words, or sentence) than the basic
# element (word). Hence the LoDTensor will hold data for three sentences of
# length 3, 4 and 2, respectively.
# which has only one lod level. Then the created LoDTensor will have only
# one higher level structure (sequence of words, or sentence) than the basic
# element (word). Hence the LoDTensor will hold data for three sentences of
# length 3, 4 and 2, respectively.
# Note that lod info should be a list of lists.
reviews_str
=
[
...
...
07.label_semantic_roles/README.cn.md
浏览文件 @
c26aa060
...
...
@@ -184,8 +184,9 @@ from __future__ import print_function
import
math
,
os
import
numpy
as
np
import
paddle
import
paddle.
v2.
dataset.conll05
as
conll05
import
paddle.dataset.conll05
as
conll05
import
paddle.fluid
as
fluid
import
six
import
time
with_gpu
=
os
.
getenv
(
'WITH_GPU'
,
'0'
)
!=
'0'
...
...
@@ -417,7 +418,7 @@ def train(use_cuda, save_dirname=None, is_local=True):
start_time
=
time
.
time
()
batch_id
=
0
for
pass_id
in
xrange
(
PASS_NUM
):
for
pass_id
in
six
.
moves
.
xrange
(
PASS_NUM
):
for
data
in
train_data
():
cost
=
exe
.
run
(
main_program
,
feed
=
feeder
.
feed
(
data
),
...
...
07.label_semantic_roles/README.md
浏览文件 @
c26aa060
...
...
@@ -207,8 +207,9 @@ from __future__ import print_function
import
math
,
os
import
numpy
as
np
import
paddle
import
paddle.
v2.
dataset.conll05
as
conll05
import
paddle.dataset.conll05
as
conll05
import
paddle.fluid
as
fluid
import
six
import
time
with_gpu
=
os
.
getenv
(
'WITH_GPU'
,
'0'
)
!=
'0'
...
...
@@ -427,7 +428,7 @@ def train(use_cuda, save_dirname=None, is_local=True):
start_time
=
time
.
time
()
batch_id
=
0
for
pass_id
in
xrange
(
PASS_NUM
):
for
pass_id
in
six
.
moves
.
xrange
(
PASS_NUM
):
for
data
in
train_data
():
cost
=
exe
.
run
(
main_program
,
feed
=
feeder
.
feed
(
data
),
...
...
07.label_semantic_roles/index.cn.html
浏览文件 @
c26aa060
...
...
@@ -226,8 +226,9 @@ from __future__ import print_function
import math, os
import numpy as np
import paddle
import paddle.
v2.
dataset.conll05 as conll05
import paddle.dataset.conll05 as conll05
import paddle.fluid as fluid
import six
import time
with_gpu = os.getenv('WITH_GPU', '0') != '0'
...
...
@@ -459,7 +460,7 @@ def train(use_cuda, save_dirname=None, is_local=True):
start_time = time.time()
batch_id = 0
for pass_id in xrange(PASS_NUM):
for pass_id in
six.moves.
xrange(PASS_NUM):
for data in train_data():
cost = exe.run(main_program,
feed=feeder.feed(data),
...
...
07.label_semantic_roles/index.html
浏览文件 @
c26aa060
...
...
@@ -249,8 +249,9 @@ from __future__ import print_function
import math, os
import numpy as np
import paddle
import paddle.
v2.
dataset.conll05 as conll05
import paddle.dataset.conll05 as conll05
import paddle.fluid as fluid
import six
import time
with_gpu = os.getenv('WITH_GPU', '0') != '0'
...
...
@@ -469,7 +470,7 @@ def train(use_cuda, save_dirname=None, is_local=True):
start_time = time.time()
batch_id = 0
for pass_id in xrange(PASS_NUM):
for pass_id in
six.moves.
xrange(PASS_NUM):
for data in train_data():
cost = exe.run(main_program,
feed=feeder.feed(data),
...
...
07.label_semantic_roles/train.py
浏览文件 @
c26aa060
...
...
@@ -3,8 +3,9 @@ from __future__ import print_function
import
math
,
os
import
numpy
as
np
import
paddle
import
paddle.
v2.
dataset.conll05
as
conll05
import
paddle.dataset.conll05
as
conll05
import
paddle.fluid
as
fluid
import
six
import
time
with_gpu
=
os
.
getenv
(
'WITH_GPU'
,
'0'
)
!=
'0'
...
...
@@ -167,7 +168,7 @@ def train(use_cuda, save_dirname=None, is_local=True):
start_time
=
time
.
time
()
batch_id
=
0
for
pass_id
in
xrange
(
PASS_NUM
):
for
pass_id
in
six
.
moves
.
xrange
(
PASS_NUM
):
for
data
in
train_data
():
cost
=
exe
.
run
(
main_program
,
feed
=
feeder
.
feed
(
data
),
fetch_list
=
[
avg_cost
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录