提交 ded22807 编写于 作者: T tangwei

rebase user

上级 c17f9aea
...@@ -18,7 +18,7 @@ train: ...@@ -18,7 +18,7 @@ train:
strategy: "async" strategy: "async"
epochs: 10 epochs: 10
workspace: "paddlerec.models.rank.text_classification" workspace: "paddlerec.models.contentunderstandin.classification"
reader: reader:
batch_size: 5 batch_size: 5
......
...@@ -26,29 +26,35 @@ import paddle.fluid.layers.control_flow as cf ...@@ -26,29 +26,35 @@ import paddle.fluid.layers.control_flow as cf
class Model(ModelBase): class Model(ModelBase):
def __init__(self, config): def __init__(self, config):
ModelBase.__init__(self, config) ModelBase.__init__(self, config)
self.dict_dim = 100
self.max_len = 10
self.cnn_dim = 32
self.cnn_filter_size = 128
self.emb_dim = 8
self.hid_dim = 128
self.class_dim = 2
def train_net(self): def train_net(self):
""" network definition """ """ network definition """
data = fluid.data(name="input", shape=[None, max_len], dtype='int64') data = fluid.data(name="input", shape=[None, self.max_len], dtype='int64')
label = fluid.data(name="label", shape=[None, 1], dtype='int64') label = fluid.data(name="label", shape=[None, 1], dtype='int64')
seq_len = fluid.data(name="seq_len", shape=[None], dtype='int64') seq_len = fluid.data(name="seq_len", shape=[None], dtype='int64')
# embedding layer # embedding layer
emb = fluid.embedding(input=data, size=[dict_dim, emb_dim]) emb = fluid.embedding(input=data, size=[self.dict_dim, self.emb_dim])
emb = fluid.layers.sequence_unpad(emb, length=seq_len) emb = fluid.layers.sequence_unpad(emb, length=self.seq_len)
# convolution layer # convolution layer
conv = fluid.nets.sequence_conv_pool( conv = fluid.nets.sequence_conv_pool(
input=emb, input=emb,
num_filters=cnn_dim, num_filters=self.cnn_dim,
filter_size=cnn_filter_size, filter_size=self.cnn_filter_size,
act="tanh", act="tanh",
pool_type="max") pool_type="max")
# full connect layer # full connect layer
fc_1 = fluid.layers.fc(input=[conv], size=hid_dim) fc_1 = fluid.layers.fc(input=[conv], size=hid_dim)
# softmax layer # softmax layer
prediction = fluid.layers.fc(input=[fc_1], size=class_dim, act="softmax") prediction = fluid.layers.fc(input=[fc_1], size=self.class_dim, act="softmax")
cost = fluid.layers.cross_entropy(input=prediction, label=label) cost = fluid.layers.cross_entropy(input=prediction, label=label)
avg_cost = fluid.layers.mean(x=cost) avg_cost = fluid.layers.mean(x=cost)
acc = fluid.layers.accuracy(input=prediction, label=label) acc = fluid.layers.accuracy(input=prediction, label=label)
...@@ -65,9 +71,7 @@ class Model(ModelBase): ...@@ -65,9 +71,7 @@ class Model(ModelBase):
def optimizer(self): def optimizer(self):
learning_rate = 0.01 learning_rate = 0.01
sgd_optimizer = fluid.optimizer.Adagrad(learning_rate=learning_rate) sgd_optimizer = fluid.optimizer.Adagrad(learning_rate=learning_rate)
return sgd_optimizer return sgd_optimizer
def infer_net(self, parameter_list): def infer_net(self, parameter_list):
self.train_net() self.train_net()
...@@ -69,14 +69,23 @@ python text2paddle.py raw_big_train_data/ raw_big_test_data/ train_big_data test ...@@ -69,14 +69,23 @@ python text2paddle.py raw_big_train_data/ raw_big_test_data/ train_big_data test
### 训练 ### 训练
```
python -m paddlerec.run -m paddlerec.models.rank.dnn -d cpu -e single
```
### 预测 ### 预测
```
python -m paddlerec.run -m paddlerec.models.rank.dnn -d cpu -e single
```
## 效果对比 ## 效果对比
### 模型效果 (测试) ### 模型效果 (测试)
| 数据集 | 模型 | loss | auc | acc | mae | | 数据集 | 模型 | loss | auc | acc | mae |
| :------------------: | :--------------------: | :---------: |:---------: | :---------: |:---------: | | :------------------: | :--------------------: | :---------: |:---------: | :---------: |:---------: |
| -- | TagSpace | -- | -- | -- | -- | | ag news dataset | TagSpace | -- | -- | -- | -- |
| -- | Classification | -- | -- | -- | -- | | -- | Classification | -- | -- | -- | -- |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册