-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean text.py and decode.py for API 2.0 #26853
Conversation
Thanks for your contribution! |
…into add-dy-decode
python/paddle/fluid/layers/rnn.py
Outdated
weight_linear = paddle.to_tensor( | ||
np.array(np.random.rand(32, 32), dtype=paddle.get_default_dtype())) | ||
trg_embeder = lambda x: F.embedding(x, weight=weight, padding_idx=0) | ||
output_layer = lambda x: F.linear(x, weight=weight_linear) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否将这里换成nn.Embedding
和nn.Linear
会更直观一些
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks
np.array(np.random.rand(32, 32), dtype=paddle.get_default_dtype())) | ||
trg_embeder = lambda x: F.embedding(x, weight=weight, padding_idx=0) | ||
output_layer = lambda x: F.linear(x, weight=weight_linear) | ||
decoder_cell = GRUCell(input_size=32, hidden_size=32) | ||
decoder = BeamSearchDecoder(decoder_cell, | ||
start_token=0, | ||
end_token=1, | ||
beam_size=4, | ||
embedding_fn=trg_embeder, | ||
output_fn=output_layer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
embedding_fn
和output_fn
是否需要调整参数命名
python/paddle/fluid/layers/rnn.py
Outdated
when using fluid.layers.embedding, must unsqueeze in embedding_fn.** | ||
**Note that paddle.nn.functional.embedding should be used here rather than | ||
paddle.nn.Embedding, since shape of ids is [batch_size, beam_size]. | ||
when using paddle.nn.Embedding, must unsqueeze in embedding_fn.** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请检查确认这里的正确性,paddle.nn.Embedding
接受的输入的形状应该是和paddle.nn.functional.embedding
一样的
output_time_major=False, | ||
impute_finished=False, | ||
is_test=False, | ||
return_length=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以考虑API中的return_length
是否可以去掉
would be called once after the decoding loop. | ||
|
||
Parameters: | ||
decoder(Decoder): An instance of `Decoder`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否需要将BeamSearchDecoder
的基类Decoder
也暴露出来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…into add-dy-decode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
python/paddle/fluid/layers/rnn.py
Outdated
decoder_cell = GRUCell(hidden_size=128) | ||
import numpy as np | ||
import paddle | ||
from paddle.fluid.layers import BeamSearchDecoder, dynamic_decode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
替换为paddle.nn下面的API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
b4a6148
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Make dynamic_decode support dygraph and expose to API 2.0 test=develop * update info about BeamSearchDecoder and dynamic_decode * remove all APIs in paddle.text, expose BeamSearchDecoder and dynamic_decode * update example code * delete test_text.py, decode.py, update some doc, fix example code float64 * delete decode import from paddle.nn * fix unittest bugs * use dygraph.Embedding instead of nn.Embedding, add paddle.enbale_static() * update, correct doc * move dynamic_decode, BeamSearchDecoder API to paddle.nn * fix code style * update unittest param, delete import pf text.py * set dtype of beamsearchtest float64 * update example code of BeamSearchDecoder, dynamic_decode Co-authored-by: LiuChiaChi <[email protected]>
* Make dynamic_decode support dygraph and expose to API 2.0 test=develop * update info about BeamSearchDecoder and dynamic_decode * remove all APIs in paddle.text, expose BeamSearchDecoder and dynamic_decode * update example code * delete test_text.py, decode.py, update some doc, fix example code float64 * delete decode import from paddle.nn * fix unittest bugs * use dygraph.Embedding instead of nn.Embedding, add paddle.enbale_static() * update, correct doc * move dynamic_decode, BeamSearchDecoder API to paddle.nn * fix code style * update unittest param, delete import pf text.py * set dtype of beamsearchtest float64 * update example code of BeamSearchDecoder, dynamic_decode Co-authored-by: LiuChiaChi <[email protected]> Co-authored-by: Guo Sheng <[email protected]>
PR types
New features
PR changes
APIs
Describe