未验证 提交 729f0c95 编写于 作者: L Li Fuchen 提交者: GitHub

unify paddle 1.6 api in understand_sentiment (#824)


* unify paddle 1.6 api in understand_sentiment
上级 1d1df8a1
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册