-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[Feat] CrossEncoder class accept prompt template parameters #3406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[Feat] CrossEncoder class accept prompt template parameters #3406
Conversation
…ple to support dynamic prompt template and default configuration. Updated CrossEncoder class to accept prompt template parameters and apply them in prediction and ranking. Added test cases to verify the functionality of prompt template and the correctness of default configuration.
|
cc @tomaarsen |
|
Hello! This is really cool! I've been planning to add support for the "decoder-style" rerankers in a future version after v5.0. For context, Sentence Transformers v5.0 is scheduled for tomorrow, and in the interest of avoiding feature creep for v5.0, I'll have a look at this in more detail after tomorrow.
|
Thank you very much! Looking forward to it |
|
Is the version upgrade going smoothly? If you have time, can you evaluate my PR? @tomaarsen |
|
So far so good re. the release!
|
|
I'm looking into potentially reusing
|
It is indeed more reasonable to reuse |
|
P.s. the latest update is that there's no convenient way to handle the truncation, nor a commonly agreed upon truncation strategy. To be as model agnostic as possible, we'd have to support various different options, but it gets quite messy quite quickly. |
|
Hello @BetterAndBetterII, Apologies for the delay. Locally, I've been working on this problem some more. Particularly, my goal is to support not just https://huggingface.co/tomaarsen/Qwen3-Reranker-0.6B-seq-cls, but also https://huggingface.co/Qwen/Qwen3-Reranker-0.6B itself. It will require a full refactor of the CrossEncoder class to be more like the SentenceTransformer/SparseEncoder classes, i.e. with modules that are executed sequentially. This allows me to create separate modules wrapping That would then also include support for templating akin to what you proposed here.
|
Summary
Best Practice
{ ... "sentence_transformers": { "version": "xxx", "prompt_template": "Instruct: {instruction}\nQuery: {query}\nDocument: {document}", "prompt_template_kwargs": { "instruction": "Given a query, find the most relevant document." } }, ... }model.predictlike normalMore customized usage
or
Test Cases:
prompt_template, passing or not should get different scoresprompt_template+prompt_template_kwargs, differentprompt_template_kwargsshould have different scoresprompt_templateand instruction configuration from config.json, differentprompt_template, instruction should have different scores, and no errors will be reportedTest Result:
Additional Example E2E Demo on Qwen3-Reranker-0.6B:
--Instruction and Correct template is very important to Qwen3-Reranker--
Misc:
which related to many issues requesting Qwen Reranker in serving vllm