Skip to content

Conversation

@yingyibiao
Copy link
Contributor

Add faq about pack_padded_sequence & pad_packed_sequence API

@paddle-bot-old
Copy link

Thanks for your contribution!


----------

##### 问题:在paddle中如何实现`torch.nn.utils.rnn.pack_padded_sequence``torch.nn.utils.rnn.pad_packed_sequence`这两个API吗?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为保持语句通顺,建议去掉"吗"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


+ 答复:目前paddle中没有和上述两个API完全对应的实现。关于torch中这两个API的详细介绍可以参考知乎上的文章 [pack_padded_sequence 和 pad_packed_sequence](https://zhuanlan.zhihu.com/p/342685890) :
`pack_padded_sequence`的功能是将mini-batch数据进行压缩,压缩掉无效的填充值,然后输入RNN网络中;`pad_packed_sequence`则是把RNN网络输出的压紧的序列再填充回来,便于进行后续的处理。
在paddle中,大家可以在GRU、LSTM等RNN网络中输入含有填充值的mini-batch数据的同时传入对应的`sequence_length`参数实现上述等价功能,具体用法可以参考 [RNN API文档](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/RNN_cn.html#rnn)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. [RNN API文档] --> [RNN]
  2. 能否给个示例代码?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. done
  2. 这个代码示例需要配合很多的torch代码,暂时先不加。

@Ligoml Ligoml merged commit fc1652e into PaddlePaddle:develop Nov 12, 2021
@yingyibiao yingyibiao deleted the docs branch November 12, 2021 10:06
RichardWooSJTU pushed a commit to RichardWooSJTU/docs that referenced this pull request Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants