[feat
] Allow loading custom modules; encode kwargs passthrough to modules
#2773
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
Pull Request overview
Details
This is an experimental branch to allow models with custom architectures to integrate with Sentence Transformers. Behind the scenes, Sentence Transformer models always rely on a list of modules, with configuration in
modules.json
. Usually, this contains aTransformer
followed by aPooler
and optionally aNormalize
and/orDense
module, but we can now fully change this up.I have two implementation formats that should both work:
forward
. Theforward
method accepts a dictionary of features from the tokenization, and then must output a dictionary. Some modules might outputsentence_embedding
, while others may outputtoken_embeddings
. The latter can then still be used with thePooling
module, which will convert the token embeddings into sentence embeddings.tomaarsen/jina-clip-implementation-st--custom_st.Transformer
, and this repository hosts custom_st.py. Otherwise, everything is the same as the other implementation.Note: you don't have to use
Transformer
orcustom_st
as names, you can be flexible here.Usage
You can now use these custom modules in Sentence Transformers directly via
trust_remote_code=True
:I believe this opens up a lot of opportunities for finetuning custom architectures, too. Even modalities not previously used with Sentence Transformers (e.g. audio?) should be totally feasible.
cc @bwanglzu