-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add FasterTokenizer on PPMiniLM #1542
Changes from 1 commit
2ca439e
51af868
67a9b82
60b8842
565df2d
7407caa
fc9097a
630451f
398557a
8dfbf58
78d5454
99455df
aed086a
1a4329d
baa4c1f
c95e5d8
f5d0f9d
f82f770
f037168
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,12 @@ def init_weights(self, layer): | |
elif isinstance(layer, nn.LayerNorm): | ||
layer._epsilon = 1e-12 | ||
|
||
def add_faster_tokenizer_op(self): | ||
self.ppminilm.tokenizer = FasterTokenizer( | ||
self.ppminilm.vocab, | ||
do_lower_case=self.ppminilm.do_lower_case, | ||
is_split_into_words=self.ppminilm.is_split_into_words) | ||
|
||
def to_static(self, | ||
output_path, | ||
use_faster_tokenizer=True, | ||
|
@@ -161,25 +167,23 @@ def to_static(self, | |
self.use_faster_tokenizer = use_faster_tokenizer | ||
# Convert to static graph with specific input description | ||
if self.use_faster_tokenizer: | ||
self.add_faster_tokenizer_op() | ||
if is_text_pair: | ||
model = paddle.jit.to_static( | ||
self, | ||
input_spec=[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么 faster 版本的输入 shape 是 [None], 非 Faster 版本的 shape 是 [None, None]? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里的 to_static 逻辑是放在 FasterPretrainedModel 里还是暴露给 FasterTokenizer 的用户比较合适?@Steffy-zxf There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
paddle.static.InputSpec( | ||
shape=[None, None], | ||
dtype=core.VarDesc.VarType.STRINGS), | ||
shape=[None], dtype=core.VarDesc.VarType.STRINGS), | ||
paddle.static.InputSpec( | ||
shape=[None, None], | ||
dtype=core.VarDesc.VarType.STRINGS) | ||
shape=[None], dtype=core.VarDesc.VarType.STRINGS) | ||
]) | ||
else: | ||
|
||
model = paddle.jit.to_static( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 基类 FasterPretrainedModel 已经实现了 to_static 函数,此处是否直接调用基类函数即可? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加入了 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已经删除了 |
||
self, | ||
input_spec=[ | ||
paddle.static.InputSpec( | ||
shape=[None, None], | ||
dtype=core.VarDesc.VarType.STRINGS) | ||
shape=[None], dtype=core.VarDesc.VarType.STRINGS) | ||
]) | ||
else: | ||
model = paddle.jit.to_static( | ||
|
@@ -283,10 +287,6 @@ def __init__(self, | |
self.is_split_into_words = is_split_into_words | ||
self.pad_token_id = pad_token_id | ||
self.initializer_range = initializer_range | ||
self.tokenizer = FasterTokenizer( | ||
self.vocab, | ||
do_lower_case=self.do_lower_case, | ||
is_split_into_words=self.is_split_into_words) | ||
weight_attr = paddle.ParamAttr( | ||
initializer=nn.initializer.TruncatedNormal( | ||
mean=0.0, std=self.initializer_range)) | ||
|
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.
函数命名 do_train -> export_model ?
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.
感谢指出,export_model和脚本名重复,为了维持一样的格式,目前改成了
do_export