Hello, I am struggling with generating a sequence of tokens using model.generate() with inputs_embeds.
For my research, I have to use inputs_embeds (word embedding vectors) instead of input_ids (token indices) as an input to the GPT2 model.
I want to employ model.generate() which is a convenient tool for generating a sequence of tokens, but there is no argument for inputs_embeds. I tried to edit " transformers.generation_utils", but it was not easy to figure out which lines I should change.
Is there any idea that I can easily generate tokens with default settings for hyper-paremeters as in model.generate()? If there is any idea, help me please.
consider you have the tensor inputs_embeds which I believe will be in the shape of (batch_size, seq_length, dim), or If you have a hidden_state in the shape of (batch_size, dim) just unsqueeze(dim=1) it to become (batch_size,1,dim)
Then smoothly u can achieve the desired output by:
create an attention mask(batch_size, seq_len)
create decoder_input_ids(batch_size, 1)
tracing these two parameters, leads to two functions below:
attention mask you are already familiar with it.
decoder_input_ids it’s ones too (multiplied by config.decoder_start_token_ids).
Hey thanks a lot for the reply and it works nice !
Slight clarification, would I need to set decoder_input_ids when I’m training the said model using inputs_embeds as well ?