Views
No views yet
| Link | |
|---|---|
| ALBERT-Base | L=12/H=768 (Base) |
| ALBERT-Large | L=24/H=1024 (Large) |
1>>> from transformers import BertTokenizer, AlbertForMaskedLM, FillMaskPipeline
2>>> tokenizer = BertTokenizer.from_pretrained("uer/albert-base-chinese-cluecorpussmall")
3>>> model = AlbertForMaskedLM.from_pretrained("uer/albert-base-chinese-cluecorpussmall")
4>>> unmasker = FillMaskPipeline(model, tokenizer)
5>>> unmasker("中国的首都是[MASK]京。")
6 [
7 {'sequence': '中 国 的 首 都 是 北 京 。',
8 'score': 0.8528032898902893,
9 'token': 1266,
10 'token_str': '北'},
11 {'sequence': '中 国 的 首 都 是 南 京 。',
12 'score': 0.07667620480060577,
13 'token': 1298,
14 'token_str': '南'},
15 {'sequence': '中 国 的 首 都 是 东 京 。',
16 'score': 0.020440367981791496,
17 'token': 691,
18 'token_str': '东'},
19 {'sequence': '中 国 的 首 都 是 维 京 。',
20 'score': 0.010197942145168781,
21 'token': 5335,
22 'token_str': '维'},
23 {'sequence': '中 国 的 首 都 是 汴 京 。',
24 'score': 0.0075391442514956,
25 'token': 3745,
26 'token_str': '汴'}
27 ]
281from transformers import BertTokenizer, AlbertModel
2tokenizer = BertTokenizer.from_pretrained("uer/albert-base-chinese-cluecorpussmall")
3model = AlbertModel.from_pretrained("uer/albert-base-chinese-cluecorpussmall")
4text = "用你喜欢的任何文本替换我。"
5encoded_input = tokenizer(text, return_tensors='pt')
6output = model(**encoded_input)1from transformers import BertTokenizer, TFAlbertModel
2tokenizer = BertTokenizer.from_pretrained("uer/albert-base-chinese-cluecorpussmall")
3model = TFAlbertModel.from_pretrained("uer/albert-base-chinese-cluecorpussmall")
4text = "用你喜欢的任何文本替换我。"
5encoded_input = tokenizer(text, return_tensors='tf')
6output = model(encoded_input)python3 preprocess.py --corpus_path corpora/cluecorpussmall_bert.txt \
--vocab_path models/google_zh_vocab.txt \
--dataset_path cluecorpussmall_albert_seq128_dataset.pt \
--seq_length 128 --processes_num 32 --data_processor albert python3 pretrain.py --dataset_path cluecorpussmall_albert_seq128_dataset.pt \
--vocab_path models/google_zh_vocab.txt \
--config_path models/albert/base_config.json \
--output_model_path models/cluecorpussmall_albert_base_seq128_model.bin \
--world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
--total_steps 1000000 --save_checkpoint_steps 100000 --report_steps 50000 \
--learning_rate 1e-4 --batch_size 64python3 preprocess.py --corpus_path corpora/cluecorpussmall_bert.txt \
--vocab_path models/google_zh_vocab.txt \
--dataset_path cluecorpussmall_albert_seq512_dataset.pt \
--seq_length 512 --processes_num 32 --data_processor albertpython3 pretrain.py --dataset_path cluecorpussmall_albert_seq512_dataset.pt \
--vocab_path models/google_zh_vocab.txt \
--pretrained_model_path models/cluecorpussmall_albert_base_seq128_model.bin-1000000 \
--config_path models/albert/base_config.json \
--output_model_path models/cluecorpussmall_albert_base_seq512_model.bin \
--world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
--total_steps 1000000 --save_checkpoint_steps 100000 --report_steps 50000 \
--learning_rate 1e-4 --batch_size 64python3 scripts/convert_albert_from_uer_to_huggingface.py --input_model_path models/cluecorpussmall_albert_base_seq512_model.bin-1000000 \
--output_model_path pytorch_model.bin@article{lan2019albert,
title={Albert: A lite bert for self-supervised learning of language representations},
author={Lan, Zhenzhong and Chen, Mingda and Goodman, Sebastian and Gimpel, Kevin and Sharma, Piyush and Soricut, Radu},
journal={arXiv preprint arXiv:1909.11942},
year={2019}
}
@article{zhao2019uer,
title={UER: An Open-Source Toolkit for Pre-training Models},
author={Zhao, Zhe and Chen, Hui and Zhang, Jinbin and Zhao, Xin and Liu, Tao and Lu, Wei and Chen, Xi and Deng, Haotang and Ju, Qi and Du, Xiaoyong},
journal={EMNLP-IJCNLP 2019},
pages={241},
year={2019}
}
@article{zhao2023tencentpretrain,
title={TencentPretrain: A Scalable and Flexible Toolkit for Pre-training Models of Different Modalities},
author={Zhao, Zhe and Li, Yudong and Hou, Cheng and Zhao, Jing and others},
journal={ACL 2023},
pages={217},
year={2023}