Skip to content

Use custom serde deserializer for JinaBERT models #559

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

Merged
merged 1 commit into from
Apr 4, 2025

Conversation

alvarobartt
Copy link
Member

What does this PR do?

Note

This PR is still being tested and is missing the tests to be included within this PR.

This PR "improves" the handling for the JinaBERT configurations as those share the same model_type as the default BERT models i.e. model_type=bert meaning that those need a specific handling for telling apart JinaBERT and BERT. Apparently, when fine-tuning or re-uploading JinaBERT models with Sentence Transformers, the _name_or_path value is overwritten with the actual path to the origin Hugging Face Hub repository, which means that the serde-based tag strategy to tell those apart will no longer work, as the value won't match the former check. This PR then, adds a custom serde deserializer to make sure that the config.json is deserialized for the correct model not only based on the _name_or_path value but also on the auto_map.AutoConfig value, which in any case will still point to the remote repository with the JinaBERT implementation.

Fixes #556

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@Narsil or @McPatate

@alvarobartt alvarobartt requested a review from Narsil April 4, 2025 13:18
@alvarobartt
Copy link
Member Author

P.S. To test this PR I've just used the same model as the one reported in the linked issue borgcollectivegmbh/testing-jina-stuff

Copy link
Collaborator

@Narsil Narsil left a comment

Choose a reason for hiding this comment

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

Very nice solution to the problem.

@Narsil Narsil merged commit 7f7832e into main Apr 4, 2025
14 checks passed
@Narsil Narsil deleted the jina-bert-config-fix branch April 4, 2025 14:10
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.

Sentence-Transformers-finetuned jinaai/jina-embeddings-v2-small-en doesn't work
2 participants