Skip to content
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

Code breaks using different model like roberta, xlm-roberta in finetuning #61

Open
Tacacs-1101 opened this issue Nov 18, 2021 · 2 comments

Comments

@Tacacs-1101
Copy link

Code breaks using a different model other than BERT. I debugged into the code and found that the code is written with respect to BERT tokenizer only while the tokenizers of other transformer models are different. Below snippet in helpers.py

if BERT_TOKENIZER is None:  # gets initialized during the first call to this method
    if bert_pretrained_name_or_path:
        BERT_TOKENIZER = transformers.BertTokenizer.from_pretrained(bert_pretrained_name_or_path)
        BERT_TOKENIZER.do_basic_tokenize = True
        BERT_TOKENIZER.tokenize_chinese_chars = False
    else:
        BERT_TOKENIZER = transformers.BertTokenizer.from_pretrained('bert-base-cased')
        BERT_TOKENIZER.do_basic_tokenize = True
        BERT_TOKENIZER.tokenize_chinese_chars = False
@UthpalaIsiru
Copy link

I also got the same issue. Anyone resolved this?

@RK-BAKU
Copy link

RK-BAKU commented Apr 20, 2023

Code breaks using a different model other than BERT. I debugged into the code and found that the code is written with respect to BERT tokenizer only while the tokenizers of other transformer models are different. Below snippet in helpers.py

if BERT_TOKENIZER is None:  # gets initialized during the first call to this method
    if bert_pretrained_name_or_path:
        BERT_TOKENIZER = transformers.BertTokenizer.from_pretrained(bert_pretrained_name_or_path)
        BERT_TOKENIZER.do_basic_tokenize = True
        BERT_TOKENIZER.tokenize_chinese_chars = False
    else:
        BERT_TOKENIZER = transformers.BertTokenizer.from_pretrained('bert-base-cased')
        BERT_TOKENIZER.do_basic_tokenize = True
        BERT_TOKENIZER.tokenize_chinese_chars = False

Faced with the same issue. This is a quick fix:

BERT_TOKENIZER = transformers.BertTokenizer.from_pretrained(bert_pretrained_name_or_path)

Replace BertTokenizer with XLMRobertaTokenizer:

BERT_TOKENIZER = transformers.XLMRobertaTokenizer.from_pretrained(bert_pretrained_name_or_path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants