Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

如何将一维向量增加lod信息,作为rnn的输入

Open yuyy0823 opened this issue 7 years ago • 4 comments

你好,使用paddle fluid 0.15版本,现在想实现一个简单的lstm,使用py_reader读入数据 image

在rnn中,通过fluid.layers.slice切片获得150为的向量,现在需要将这个向量转换为10*15的序列格式,10可以理解为一句话中的10个词,15是词的维度,现在这样实现运行报错,试了很多方法都不太行,求指导! image

报错信息如下 image

yuyy0823 avatar Jun 11 '19 09:06 yuyy0823

lod_reset的api示例请参考:http://www.paddlepaddle.org/documentation/docs/zh/1.4/api_cn/layers_cn.html#lod-reset

获得150为的向量,现在需要将这个向量转换为10*15的序列格式,10可以理解为一句话中的10个词,15是词的维度

lod_reset是在词上面做的,无关乎词的维度。如果仅仅要变成[10,15],用reshape可以么?可以参考下:https://github.com/PaddlePaddle/Paddle/issues/15289#issuecomment-494683444

luotao1 avatar Jun 11 '19 12:06 luotao1

就是按照lod_reset的api示例写的,用reshape还是不包含序列信息,运行还是有问题,现在就是想把这个150维特征变成可以传给lstm的数据格式,不知道怎么转换数据格式。

yuyy0823 avatar Jun 12 '19 02:06 yuyy0823

  1. 首先150维的向量需要reshape成[10,15]的。
  2. reshape后不包含序列信息,因此reshape后要用lod_reset来加。从问题看,只有一条句子10个词,因此y.lod=[[0, 10]]。

luotao1 avatar Jun 12 '19 03:06 luotao1

请问怎么设置y.lod=[[0, 10]]啊,现在这么写还是不对 image

应该是这条语句不对 seg_feats_new = fluid.layers.data(name='y', shape=[0, 10], lod_level=1) 能给个正确写法吗?

yuyy0823 avatar Jun 12 '19 05:06 yuyy0823