ModernBERT icon indicating copy to clipboard operation
ModernBERT copied to clipboard

Doesn't support input vector? There is no inputs_embeds

Open znsoftm opened this issue 11 months ago • 6 comments

in the parameter list of forward, there is no inputs_embeds parameter, so it doesn't support inputing vector (embedding vector not token id)?

znsoftm avatar Dec 28 '24 03:12 znsoftm

To be compatible with Bert-base/large, need a new parameter inputs_embeds to accept vectors as input.

znsoftm avatar Dec 28 '24 21:12 znsoftm

Hello,

Indeed, BertModel allows to pass inputs_embeds instead of input_ids, which effectively skip the embedding lookup layer and directly use the input tensor.

This could be added to ModernBERT by adding the same logic to ModernBertModel and forwarding it to ModernBertEmbeddings, which would end up being only a norm + dropout layer in such cases. Every subclass would also need to have this parameter and forward it to their respective ModernBertModel.

May I ask what is your use case for this? For VLM (or LLM, for that matter), I get that you might want to have some liberty on what you can feed the model, but here I am not sure I see why you would not use the embeddings layer directly? It should be added anyways for retro-compatiblity, but I am curious about todays use cases.

NohTow avatar Dec 29 '24 11:12 NohTow

I have done a research for binary file identification, originally it is based on bert-base/large. I would like to transfer it to ModernBert to determine the potential of our methods.

znsoftm avatar Dec 30 '24 08:12 znsoftm

It is like a VLM, align binary data to language vector.

znsoftm avatar Dec 30 '24 08:12 znsoftm

Cool, thanks for the input! FYI, this feature is already being implemented to support Contextual Document Embeddings model in this PR (I did not realize this was how it was implemented in transformers), so it should be available soon!

NohTow avatar Dec 30 '24 13:12 NohTow

Thanks for your time.

znsoftm avatar Dec 31 '24 07:12 znsoftm

Hello, closing this as the PR has been merged. Feel free to re-open if something is not working!

NohTow avatar Jan 14 '25 13:01 NohTow