Skip to content
Advertisement

How to input embeddings directly to a huggingface model instead of tokens?

I’m going over the huggingface tutorial where they showed how tokens can be fed into a model to generate hidden representations:

JavaScript

But how can I input word embeddings directly instead of tokens? That is, I have another model that generates word embeddings and I need to feed those into the model

Advertisement

Answer

Most (every?) huggingface encoder model supports that with the parameter inputs_embeds:

JavaScript

P.S.: Don’t forget the attention mask in case this is required.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement