

TITLE
How to generate data using beam search from a custom gpt2 model?

COMMENTS
6

REACTIONS
+1: 0
-1: 0
laugh: 0
hooray: 0
heart: 0
rocket: 0
eyes: 0

BODY
# ❓ Questions & Help

<!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to the Hugging Face forum: https://discuss.huggingface.co/ .
     You can also try Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. In this case, make sure to tag your
     question with the right deep learning framework as well as the
     huggingface-transformers tag: 
     https://stackoverflow.com/questions/tagged/huggingface-transformers 
     -->

## Details
I have a custom model with classification and an LM head.
`
        

        self.config = AutoConfig.from_pretrained("gpt2", num_labels=3)
        self.base_model = AutoModel.from_pretrained("gpt2", config=self.config)
        self.classifier = nn.Sequential(
            nn.Linear(self.config.hidden_size, self.config.num_labels),
        )

        self.lm_head = nn.Linear(self.base_model.config.n_embd, self.base_model.config.vocab_size, bias=False)`

I want to generate the sentences using this model (given the initial prefix) via beam search.
How can I achieve that?

I know that LM with double head exists but it's not fit for my usecase