brightmart / roberta_zh

RoBERTa中文预训练模型: RoBERTa for Chinese
2.6k stars 409 forks source link

Use Roberta in pytorch transformers #39

Open Vimos opened 5 years ago

Vimos commented 5 years ago

I have been using BertPreTrainedModel to load this roberta model, which works well.

Noticing in pytorch_transformers, Roberta is also supported.

from pytorch_transformers import (BertConfig, BertTokenizer,
                                  RobertaConfig, RobertaTokenizer)

Should I switch to Roberta? If so, what to use for the parameter merges_file in RobertaTokenizer?

brightmart commented 5 years ago

no. this roberta_zh is changed based on bert with main ideas from RoBERTa paper, but it may not compatible to roberta pytorch implementation from facebook ai project. so load from BertPreTrainedModel should be right way.

can you paste code here to show how you load roberta_zh using BertPreTrainedModel, and how you use it.

(anyway you can have a try, but it should be failed)

Vimos commented 5 years ago

It's the same with original pytorch-transformers

bert_config = MODEL_CLASSES[args.model_type][0].from_json_file(args.bert_config_file)
tokenizer = MODEL_CLASSES[args.model_type][2](vocab_file=args.vocab_file, 
do_lower_case=args.do_lower_case)
model = MODEL_CLASSES[args.model_type][1].from_pretrained(args.model_name_or_path,
                from_tf=bool('.ckpt' in args.model_name_or_path), config=bert_config)

However, for RobertaTokenizer, you cannot use it to load roberta_zh.

brightmart commented 5 years ago

yeah, it is.

mayktian commented 4 years ago

can you please suggest which pytorch bert package is compatible with this pre-trained model? I had the same failure as Vimos when loading it with facebook transformers.

brightmart commented 4 years ago

roberta is bert,you can load roberta use pytorch transformer, select model as bert