-
Notifications
You must be signed in to change notification settings - Fork 3k
Best Practice
骑马小猫 edited this page Nov 3, 2022
·
7 revisions
这里将介绍使用PaddleNLP过程中的最佳实践方法,形式不限于代码片段和github repo,也欢迎大家来贡献自己的实践方法。
from paddlenlp.transformers import BertConfig, BertModel, BertForTokenClassification
from paddlenlp.utils.converter import Converter, StateDictKeysChecker
config = BertConfig()
bert_model = BertModel(config)
bert_for_token_model = BertForTokenClassification(config)
# base-downstream
checker = StateDictKeysChecker(
bert_model, Converter.get_model_state_dict(bert_for_token_model))
unexpected_keys = checker.get_unexpected_keys()
assert len(unexpected_keys) == 2
mismatched_keys = checker.get_mismatched_keys()
assert len(mismatched_keys) == 0