Skip to content

feat: add instruct wrapper#1768

Merged
Samoed merged 13 commits into
mainfrom
instruct_sentence_transformer_wrapper
Jan 25, 2025
Merged

feat: add instruct wrapper#1768
Samoed merged 13 commits into
mainfrom
instruct_sentence_transformer_wrapper

Conversation

@Samoed

@Samoed Samoed commented Jan 11, 2025

Copy link
Copy Markdown
Member

Checklist

  • Run tests locally to make sure nothing is broken using make test.
  • Run the formatter to format the code using make lint.

Add InstructWrapper that uses SentenceTransformer models

@Samoed Samoed changed the title add instruct wrapper feat: add instruct wrapper Jan 11, 2025
@Samoed Samoed mentioned this pull request Jan 12, 2025
7 tasks
Comment thread mteb/models/instruct_wrapper.py Outdated
Comment thread mteb/models/instruct_wrapper.py Outdated
@Samoed Samoed requested a review from isaac-chung January 22, 2025 09:28
…pper

# Conflicts:
#	mteb/models/jasper_models.py
@isaac-chung

Copy link
Copy Markdown
Collaborator

Thanks for the effort!

Following up on [this comment] (#1768 (comment)) from @KennethEnevoldsen, it's not quite clear in this PR why this new wrapper is needed, and why we cannot support prompts in the existing ST wrapper. If there was an existing discussion, it would be great to link here.

Could we please add an explanation clearly with code examples in the PR description (since there's no issue reference), and also a short line in the docstrings?

@Samoed

Samoed commented Jan 24, 2025

Copy link
Copy Markdown
Member Author

@isaac-chung This wrapper is designed for models that use prompts to generate embeddings. Previously, this was handled by InstructWrapper, but it relied on gritlm, which can be a bit difficult for newcomers to understand. A similar wrapper was used with the Jasper model, which was initially included in this PR. However, I removed it because it used s2p to decide whether to apply a passage prompt or not, and I wanted to keep this PR more reproducible.

I didn't add this functionality to SentenceTransformerWrapper because I believe it’s easier to have a separate wrapper specifically for models using instructions and prefixes. I'm not sure what kind of code example you're looking for, as this wrapper works similarly to all other wrappers.

@isaac-chung

Copy link
Copy Markdown
Collaborator

Thanks for the explanation and the effort you put into this! I think this is a good step forward, but I have a few follow-up questions to help clarify things further:

  1. Could we provide more guidance on how users should choose between the gritlm-instruct wrapper and the new instruct wrapper? Having two separate wrappers might introduce some confusion, so it would help to clarify their use cases. For example, are there any user feedback or specific scenarios that prompted this change?

  2. I noticed there is only one file changed in this PR. Could you elaborate on what you mean by 'reproducible' here? A bit more context would help me understand how this is addressed.

  3. Lastly, could you share more details on why this approach (a separate wrapper) is easier or preferable compared to extending the existing SentenceTransformerWrapper? If there are challenges in doing so, it would be helpful to document them for context.

@Samoed

Samoed commented Jan 24, 2025

Copy link
Copy Markdown
Member Author

Firstly, I made a PR to add the InstructSentenceTransformerWrapper as a replacement for the JasperWrapper. However, during the review, this turned into a discussion.

  1. I believe we can deprecate (or just don't apply to new models) the GritLM and primarily use the SentenceTransformer. The GritLM is difficult to understand because it’s unclear what certain parameters mean. For example, it’s not obvious what [attn = "cccc"] represents. Additionally, GritLM uses AutoModel for loading models, but now there are models (like Jasper) that rely on custom classes automatically supported by SentenceTransformer. These cannot be run with GritLMWrapper.

  2. The authors of Jasper apply instructions based on whether the task involves passages or not and also check if the task is an s2s task (source).

  3. Combining wrappers that handle both prefixes and instructions could be confusing, as they involve different logic (e.g., applying prompts, adding special tokens, etc.). Keeping them separate would make it easier to maintain and avoid mixing their distinct behaviors.

@isaac-chung isaac-chung left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation, this makes complete sense now, and I agree with your approach.

I think adding a section to the README file to document the purpose and usage of the new wrapper would be a great final step. This will help users quickly understand how and when to use it compared to other wrappers.

Great work!

Comment thread mteb/models/instruct_wrapper.py Outdated
Comment thread mteb/models/instruct_wrapper.py Outdated
Comment thread mteb/models/instruct_wrapper.py Outdated
Comment thread mteb/models/instruct_wrapper.py Outdated
Samoed and others added 3 commits January 25, 2025 13:59
@Samoed

Samoed commented Jan 25, 2025

Copy link
Copy Markdown
Member Author

I think we shouldn’t add this to the README because I don’t believe wrappers should be included there. Instead, it’s better to add it to docs/adding_a_model, as this change is more developer-focused than user-focused.

@Samoed Samoed requested a review from isaac-chung January 25, 2025 11:23

@isaac-chung isaac-chung left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. 2 small suggestions and I think we're set here. Thanks again!

Comment thread docs/adding_a_model.md Outdated
Comment thread mteb/models/instruct_wrapper.py Outdated
Co-authored-by: Isaac Chung <chungisaac1217@gmail.com>
@isaac-chung

Copy link
Copy Markdown
Collaborator

Good to merge 🙌

@Samoed Samoed enabled auto-merge (squash) January 25, 2025 16:34
@Samoed Samoed merged commit ee0f15a into main Jan 25, 2025
@Samoed Samoed deleted the instruct_sentence_transformer_wrapper branch January 25, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants