load_transformer_tokenizer(
'voidful/albert_chinese_tiny', 'BertTokenizer')
config = load_transformer_config(
'bert-base-chinese')
config_dict = config.to_dict()
# load config with dict
config = load_transformer_config(
config_dict, load_module_name='BertConfig')
# this is a pt only model
model = load_transformer_model(
'voidful/albert_chinese_tiny')
# load by config (not load weights)
model = load_transformer_model(load_transformer_config(
'bert-base-chinese'), 'TFBertModel')
le_train = get_or_make_label_encoder(
params=params, problem='weibo_fake_ner', mode=m3tl.TRAIN, label_list=[['a', 'b'], ['c']]
)
# seq_tag will add [PAD]
assert len(le_train.encode_dict) == 4, le_train.encode_dict
le_predict = get_or_make_label_encoder(
params=params, problem='weibo_fake_ner', mode=m3tl.PREDICT)
assert le_predict.encode_dict==le_train.encode_dict
# list train
le_train = get_or_make_label_encoder(
params=params, problem='weibo_fake_cls', mode=m3tl.TRAIN, label_list=['a', 'b', 'c']
)
# seq_tag will add [PAD]
assert len(le_train.encode_dict) == 3
le_predict = get_or_make_label_encoder(
params=params, problem='weibo_fake_cls', mode=m3tl.PREDICT)
assert le_predict.encode_dict==le_train.encode_dict
# text
le_train = get_or_make_label_encoder(
params=params, problem='weibo_masklm', mode=m3tl.TRAIN)
assert isinstance(le_train, transformers.PreTrainedTokenizer)
le_predict = get_or_make_label_encoder(
params=params, problem='weibo_masklm', mode=m3tl.PREDICT)
assert isinstance(le_predict, transformers.PreTrainedTokenizer)
test_dict = {
'test1': np.random.uniform(size=(64, 32)),
'test2': np.array([1, 2, 3], dtype='int32'),
'test5': 5
}
desc_dict = infer_shape_and_type_from_dict(
test_dict)
assert desc_dict == ({'test1': [None, 32], 'test2': [None], 'test5': []}, {
'test1': tf.float32, 'test2': tf.int32, 'test5': tf.int32})
model = load_transformer_model(
'voidful/albert_chinese_tiny')
main_model = get_transformer_main_model(model)
isinstance(main_model, transformers.TFAlbertMainLayer)
embedding = get_embedding_table_from_model(
model)
assert embedding.shape == (21128, 128)