How to generate data using beam search from a custom gpt2 model?
See original GitHub issue❓ Questions & Help
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
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to generate text: using different decoding methods for ...
We will give a tour of the currently most prominent decoding methods, mainly Greedy search, Beam search, Top-K sampling and Top-p sampling.
Read more >Constrained Beam Search with Transformers
The new constrained beam search feature with the new force_words_ids argument to the model.generate() function allows us to do exactly that!
Read more >Text generation with GPT-2 - Model Differently
In this post we will see how to generate text with models based on the Transformers architecture, and we will use this knowledge...
Read more >Text Generation with HuggingFace - GPT2 | Kaggle
In this notebook, I will explore text generation using a GPT-2 model, ... To use Beam Search, we need only modify some parameters...
Read more >Much More Quickly and Easily Deploy GPT-2 Using Aitextgen
For example, the user can provide a training dataset, which is used to train the model. Subsequently, the model can then be used...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I would recommend you check the source code for the
generate
method and see how the beam search is implemented. It is not trivial, however.Maybe @sshleifer and @patrickvonplaten have better tips on how to best do this.
@nrjvarshney Did you find any suitable way to use
generate
function for a custom model? I am facing a similar issue with a model of mine, and would be really grateful if you could let me know how to solve the issue.