question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I initialize RobertaForSequenceClassification empty?

See original GitHub issue

I am having my own custom dataset which is completely different from the one with roberta. Now using ByteLevelBPETokenizer, I am creating vocab.json and merges.txt . I am using these two to files to initialize RobertaTokenizerFast for encoding my corpus. Now I am training a RobertaForSequenceClassification for a binary classification problem. When I am initializing RobertaForSequenceClassification with any of the pre-trained models I am getting IndexError: index out of range in self on the RAM while on GPU I am getting RuntimeError: CUDA error: an illegal memory access was encountered . I have followed other issues but of no help. My understanding since I am creating my own vocabulary, some of the tokens are not in pre-trained model. So is there a way to initialize RobertaForSequenceClassification empty or to train this classification model for my dataset?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
SergioBarretoJrcommented, Sep 10, 2020

@SergioBarretoJr I am also facing the same issue, can you please help me?

@amandalmia14 Have you ever checked if you set vocab size equal in tokenizer and RoBERTa.config file?

def train_tokenizer(self,file_path,outDir):
    # Initialize a tokenizer
    tokenizer = ByteLevelBPETokenizer()
    # Customize training
    tokenizer.train(files=file_path, **vocab_size=52_000**, min_frequency=2, special_tokens=[
        "<s>",
        "<pad>",
        "</s>",
        "<unk>",
        "<mask>",
    ])
    self.tokenizer=tokenizer
    tokenizer.save(outDir)

This was how I solver my issue. Can I help with something more?

1reaction
LysandreJikcommented, Jun 18, 2020

Hi! If you want to initialize a new RobertaForSequenceClassification model you can do so as such:

from transformers import RobertaForSequenceClassification, RobertaConfig

config = RobertaConfig(
    # put the args you need, like the vocab size
    vocab_size=100
)

model = RobertaForSequenceClassification(config)
Read more comments on GitHub >

github_iconTop Results From Across the Web

RoBERTa - Hugging Face
Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the from_pretrained() method to...
Read more >
class - RoBertaForSequenceClassification - Spark NLP
RoBertaForSequenceClassification can load RoBERTa Models with sequence classification/regression head on top (a linear layer on top of the pooled output) ...
Read more >
Using Roberta classification head for fine-tuning a pre-trained ...
An example to show how we can use Huggingface Roberta Model for fine-tuning a classification task starting from a pre-trained model.
Read more >
Python: BERT Error - Some weights of the model checkpoint at ...
initializing a BertForSequenceClassification model from a BertForPreTraining model).
Read more >
Model Training + roberta -base - Kaggle
Time # Log Message 11.8s 1 /kaggle/input/roberta‑base/rust_model.ot 11.8s 2 /kaggle/input/roberta‑base/config.json 11.8s 3 /kaggle/input/roberta‑base/merges.txt
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found