Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
729f0c95
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看板
未验证
提交
729f0c95
编写于
10月 14, 2019
作者:
L
Li Fuchen
提交者:
GitHub
10月 14, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
unify paddle 1.6 api in understand_sentiment (#824)
* unify paddle 1.6 api in understand_sentiment
上级
1d1df8a1
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
14 addition
and
21 deletion
+14
-21
06.understand_sentiment/README.cn.md
06.understand_sentiment/README.cn.md
+2
-3
06.understand_sentiment/README.md
06.understand_sentiment/README.md
+2
-3
06.understand_sentiment/index.cn.html
06.understand_sentiment/index.cn.html
+2
-3
06.understand_sentiment/index.html
06.understand_sentiment/index.html
+2
-3
06.understand_sentiment/train_conv.py
06.understand_sentiment/train_conv.py
+2
-3
06.understand_sentiment/train_dyn_rnn.py
06.understand_sentiment/train_dyn_rnn.py
+2
-3
06.understand_sentiment/train_stacked_lstm.py
06.understand_sentiment/train_stacked_lstm.py
+2
-3
未找到文件。
06.understand_sentiment/README.cn.md
浏览文件 @
729f0c95
...
...
@@ -219,8 +219,7 @@ def stacked_lstm_net(data, input_dim, class_dim, emb_dim, hid_dim, stacked_num):
```
python
def
inference_program
(
word_dict
):
data
=
fluid
.
data
(
name
=
"words"
,
shape
=
[
-
1
],
dtype
=
"int64"
,
lod_level
=
1
)
name
=
"words"
,
shape
=
[
None
],
dtype
=
"int64"
,
lod_level
=
1
)
dict_dim
=
len
(
word_dict
)
net
=
convolution_net
(
data
,
dict_dim
,
CLASS_DIM
,
EMB_DIM
,
HID_DIM
)
# net = stacked_lstm_net(data, dict_dim, CLASS_DIM, EMB_DIM, HID_DIM, STACKED_NUM)
...
...
@@ -235,7 +234,7 @@ def inference_program(word_dict):
```
python
def
train_program
(
prediction
):
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
-
1
,
1
],
dtype
=
"int64"
)
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
cost
)
accuracy
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
...
...
06.understand_sentiment/README.md
浏览文件 @
729f0c95
...
...
@@ -208,8 +208,7 @@ Next we define the prediction program (`inference_program`). We use `convolution
```
python
def
inference_program
(
word_dict
):
data
=
fluid
.
data
(
name
=
"words"
,
shape
=
[
-
1
],
dtype
=
"int64"
,
lod_level
=
1
)
name
=
"words"
,
shape
=
[
None
],
dtype
=
"int64"
,
lod_level
=
1
)
dict_dim
=
len
(
word_dict
)
net
=
convolution_net
(
data
,
dict_dim
,
CLASS_DIM
,
EMB_DIM
,
HID_DIM
)
# net = stacked_lstm_net(data, dict_dim, CLASS_DIM, EMB_DIM, HID_DIM, STACKED_NUM)
...
...
@@ -224,7 +223,7 @@ During the testing, the classifier calculates the probability of each output. Th
```
python
def
train_program
(
prediction
):
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
-
1
,
1
],
dtype
=
"int64"
)
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
cost
)
accuracy
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
...
...
06.understand_sentiment/index.cn.html
浏览文件 @
729f0c95
...
...
@@ -261,8 +261,7 @@ def stacked_lstm_net(data, input_dim, class_dim, emb_dim, hid_dim, stacked_num):
```python
def inference_program(word_dict):
data = fluid.data(
name="words", shape=[-1], dtype="int64", lod_level=1)
name="words", shape=[None], dtype="int64", lod_level=1)
dict_dim = len(word_dict)
net = convolution_net(data, dict_dim, CLASS_DIM, EMB_DIM, HID_DIM)
# net = stacked_lstm_net(data, dict_dim, CLASS_DIM, EMB_DIM, HID_DIM, STACKED_NUM)
...
...
@@ -277,7 +276,7 @@ def inference_program(word_dict):
```python
def train_program(prediction):
label = fluid.data(name="label", shape=[
-1,
1], dtype="int64")
label = fluid.data(name="label", shape=[
None,
1], dtype="int64")
cost = fluid.layers.cross_entropy(input=prediction, label=label)
avg_cost = fluid.layers.mean(cost)
accuracy = fluid.layers.accuracy(input=prediction, label=label)
...
...
06.understand_sentiment/index.html
浏览文件 @
729f0c95
...
...
@@ -250,8 +250,7 @@ Next we define the prediction program (`inference_program`). We use `convolution
```python
def inference_program(word_dict):
data = fluid.data(
name="words", shape=[-1], dtype="int64", lod_level=1)
name="words", shape=[None], dtype="int64", lod_level=1)
dict_dim = len(word_dict)
net = convolution_net(data, dict_dim, CLASS_DIM, EMB_DIM, HID_DIM)
# net = stacked_lstm_net(data, dict_dim, CLASS_DIM, EMB_DIM, HID_DIM, STACKED_NUM)
...
...
@@ -266,7 +265,7 @@ During the testing, the classifier calculates the probability of each output. Th
```python
def train_program(prediction):
label = fluid.data(name="label", shape=[
-1
, 1], dtype="int64")
label = fluid.data(name="label", shape=[
None
, 1], dtype="int64")
cost = fluid.layers.cross_entropy(input=prediction, label=label)
avg_cost = fluid.layers.mean(cost)
accuracy = fluid.layers.accuracy(input=prediction, label=label)
...
...
06.understand_sentiment/train_conv.py
浏览文件 @
729f0c95
...
...
@@ -62,14 +62,13 @@ def convolution_net(data, input_dim, class_dim, emb_dim, hid_dim):
def
inference_program
(
word_dict
):
dict_dim
=
len
(
word_dict
)
data
=
fluid
.
data
(
name
=
"words"
,
shape
=
[
-
1
],
dtype
=
"int64"
,
lod_level
=
1
)
data
=
fluid
.
data
(
name
=
"words"
,
shape
=
[
None
],
dtype
=
"int64"
,
lod_level
=
1
)
net
=
convolution_net
(
data
,
dict_dim
,
CLASS_DIM
,
EMB_DIM
,
HID_DIM
)
return
net
def
train_program
(
prediction
):
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
-
1
,
1
],
dtype
=
"int64"
)
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
cost
)
accuracy
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
...
...
06.understand_sentiment/train_dyn_rnn.py
浏览文件 @
729f0c95
...
...
@@ -53,15 +53,14 @@ def dynamic_rnn_lstm(data, input_dim, class_dim, emb_dim, lstm_size):
def
inference_program
(
word_dict
):
data
=
fluid
.
data
(
name
=
"words"
,
shape
=
[
-
1
],
dtype
=
"int64"
,
lod_level
=
1
)
data
=
fluid
.
data
(
name
=
"words"
,
shape
=
[
None
],
dtype
=
"int64"
,
lod_level
=
1
)
dict_dim
=
len
(
word_dict
)
pred
=
dynamic_rnn_lstm
(
data
,
dict_dim
,
CLASS_DIM
,
EMB_DIM
,
LSTM_SIZE
)
return
pred
def
train_program
(
prediction
):
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
-
1
,
1
],
dtype
=
"int64"
)
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
cost
)
accuracy
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
...
...
06.understand_sentiment/train_stacked_lstm.py
浏览文件 @
729f0c95
...
...
@@ -68,8 +68,7 @@ def stacked_lstm_net(data, input_dim, class_dim, emb_dim, hid_dim, stacked_num):
def
inference_program
(
word_dict
):
data
=
fluid
.
data
(
name
=
"words"
,
shape
=
[
-
1
],
dtype
=
"int64"
,
lod_level
=
1
)
data
=
fluid
.
data
(
name
=
"words"
,
shape
=
[
None
],
dtype
=
"int64"
,
lod_level
=
1
)
dict_dim
=
len
(
word_dict
)
net
=
stacked_lstm_net
(
data
,
dict_dim
,
CLASS_DIM
,
EMB_DIM
,
HID_DIM
,
STACKED_NUM
)
...
...
@@ -78,7 +77,7 @@ def inference_program(word_dict):
def
train_program
(
prediction
):
# prediction = inference_program(word_dict)
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
-
1
,
1
],
dtype
=
"int64"
)
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
cost
)
accuracy
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录