api文档的layers.lstm错误
收藏
运行飞桨的lstm例子报错
Traceback (most recent call last):
File "/home/c/my/competition/DuEE_baseline/DuEE-PaddleHub/tesy1.py", line 18, in
rnn_out, last_h, last_c = layers.lstm(emb, init_h, init_c, max_len, hidden_size, num_layers, dropout_prob=dropout_prob)
File "/home/c/anaconda3/envs/python27/lib/python2.7/site-packages/paddle/fluid/layers/rnn.py", line 2163, in lstm
persistable=True, type=core.VarDesc.VarType.RAW, stop_gradient=True)
NameError: global name 'core' is not defined
Process finished with exit code 1
以下是代码
import paddle.fluid as fluid
import paddle.fluid.layers as layers
emb_dim = 256
vocab_size = 10000
data = fluid.layers.data(name='x', shape=[-1, 100, 1],
dtype='int64')
emb = fluid.layers.embedding(input=data, size=[vocab_size, emb_dim], is_sparse=True)
batch_size = 20
max_len = 100
dropout_prob = 0.2
seq_len = 100
hidden_size = 150
num_layers = 1
init_h = layers.fill_constant( [num_layers, batch_size, hidden_size], 'float32', 0.0 )
init_c = layers.fill_constant( [num_layers, batch_size, hidden_size], 'float32', 0.0 )
rnn_out, last_h, last_c = layers.lstm(emb, init_h, init_c, max_len, hidden_size, num_layers, dropout_prob=dropout_prob)
rnn_out.shape # (-1, 100, 150)
last_h.shape # (1, 20, 150)
last_c.shape # (1, 20, 150)
有没有好心人帮忙解答下?O(∩_∩)O谢谢
0
收藏
请登录后评论
参考一下dynamic_lstm:
这个问题建议去官方github提issue我试了一下官方的exmaple在paddle1.7.1环境下也有错,官方例子如下